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