1 2 /* 3 Code for manipulating files. 4 */ 5 #include <petscsys.h> 6 #if defined(PETSC_HAVE_WINDOWS_H) 7 #include <windows.h> 8 #endif 9 10 #if defined(PETSC_HAVE_GET_USER_NAME) 11 #undef __FUNCT__ 12 #define __FUNCT__ "PetscGetUserName" 13 PetscErrorCode PetscGetUserName(char name[],size_t nlen) 14 { 15 PetscFunctionBegin; 16 GetUserName((LPTSTR)name,(LPDWORD)(&nlen)); 17 PetscFunctionReturn(0); 18 } 19 20 #else 21 #undef __FUNCT__ 22 #define __FUNCT__ "PetscGetUserName" 23 /*@C 24 PetscGetUserName - Returns the name of the user. 25 26 Not Collective 27 28 Input Parameter: 29 nlen - length of name 30 31 Output Parameter: 32 . name - contains user name. Must be long enough to hold the name 33 34 Level: developer 35 36 Concepts: user name 37 38 .seealso: PetscGetHostName() 39 @*/ 40 PetscErrorCode PetscGetUserName(char name[],size_t nlen) 41 { 42 const char *user; 43 PetscErrorCode ierr; 44 45 PetscFunctionBegin; 46 user = getenv("USER"); 47 if (!user) user = "Unknown"; 48 ierr = PetscStrncpy(name,user,nlen);CHKERRQ(ierr); 49 PetscFunctionReturn(0); 50 } 51 #endif 52