1 2 /* 3 Code for manipulating files. 4 */ 5 #include <petscsys.h> 6 #if defined(PETSC_HAVE_PWD_H) 7 #include <pwd.h> 8 #endif 9 #include <ctype.h> 10 #include <sys/stat.h> 11 #if defined(PETSC_HAVE_SYS_UTSNAME_H) 12 #include <sys/utsname.h> 13 #endif 14 #if defined(PETSC_HAVE_WINDOWS_H) 15 #include <windows.h> 16 #endif 17 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H) 18 #include <sys/systeminfo.h> 19 #endif 20 #if defined(PETSC_HAVE_UNISTD_H) 21 #include <unistd.h> 22 #endif 23 24 25 #if defined(PETSC_HAVE_GET_USER_NAME) 26 #undef __FUNCT__ 27 #define __FUNCT__ "PetscGetUserName" 28 PetscErrorCode PetscGetUserName(char name[],size_t nlen) 29 { 30 PetscFunctionBegin; 31 GetUserName((LPTSTR)name,(LPDWORD)(&nlen)); 32 PetscFunctionReturn(0); 33 } 34 35 #elif defined(PETSC_HAVE_PWD_H) 36 #undef __FUNCT__ 37 #define __FUNCT__ "PetscGetUserName" 38 /*@C 39 PetscGetUserName - Returns the name of the user. 40 41 Not Collective 42 43 Input Parameter: 44 nlen - length of name 45 46 Output Parameter: 47 . name - contains user name. Must be long enough to hold the name 48 49 Level: developer 50 51 Concepts: user name 52 53 .seealso: PetscGetHostName() 54 @*/ 55 PetscErrorCode PetscGetUserName(char name[],size_t nlen) 56 { 57 struct passwd *pw=0; 58 PetscErrorCode ierr; 59 60 PetscFunctionBegin; 61 #if defined(PETSC_HAVE_GETPWUID) 62 pw = getpwuid(getuid()); 63 #endif 64 if (!pw) {ierr = PetscStrncpy(name,"Unknown",nlen);CHKERRQ(ierr);} 65 else {ierr = PetscStrncpy(name,pw->pw_name,nlen);CHKERRQ(ierr);} 66 PetscFunctionReturn(0); 67 } 68 69 #else 70 71 #undef __FUNCT__ 72 #define __FUNCT__ "PetscGetUserName" 73 PetscErrorCode PetscGetUserName(char *name,size_t nlen) 74 { 75 PetscErrorCode ierr; 76 77 PetscFunctionBegin; 78 ierr = PetscStrncpy(name,"Unknown",nlen);CHKERRQ(ierr); 79 PetscFunctionReturn(0); 80 } 81 #endif /* !PETSC_HAVE_PWD_H */ 82 83