Actual source code: fuser.c

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

      9: #if defined(PETSC_HAVE_GET_USER_NAME)
     10: PetscErrorCode PetscGetUserName(char name[], size_t nlen)
     11: {
     12:   PetscFunctionBegin;
     13:   GetUserName((LPTSTR)name, (LPDWORD)(&nlen));
     14:   PetscFunctionReturn(PETSC_SUCCESS);
     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:   PetscFunctionBegin;
     38:   user = getenv("USER");
     39:   if (!user) user = "Unknown";
     40:   PetscCall(PetscStrncpy(name, user, nlen));
     41:   PetscFunctionReturn(PETSC_SUCCESS);
     42: }
     43: #endif