Actual source code: fuser.c


  2: /*
  3:       Code for manipulating files.
  4: */
  5: #include <petscsys.h>
  6: #if defined(PETSC_HAVE_WINDOWS_H)
  7:   #include <windows.h>
  8: #endif

 10: #if defined(PETSC_HAVE_GET_USER_NAME)
 11: PetscErrorCode PetscGetUserName(char name[], size_t nlen)
 12: {
 13:   GetUserName((LPTSTR)name, (LPDWORD)(&nlen));
 14:   return 0;
 15: }

 17: #else
 18: /*@C
 19:     PetscGetUserName - Returns the name of the user.

 21:     Not Collective

 23:     Input Parameter:
 24:     nlen - length of name

 26:     Output Parameter:
 27: .   name - contains user name.  Must be long enough to hold the name

 29:     Level: developer

 31: .seealso: `PetscGetHostName()`
 32: @*/
 33: PetscErrorCode PetscGetUserName(char name[], size_t nlen)
 34: {
 35:   const char *user;

 37:   user = getenv("USER");
 38:   if (!user) user = "Unknown";
 39:   PetscStrncpy(name, user, nlen);
 40:   return 0;
 41: }
 42: #endif