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