Date: 2025-03-29T05:58:46+00:00

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:   Fortran Note:
     32: .vb
     33:   character*(32) str
     34:   call PetscGetUserName(str,ierr)
     35: .ve

     37: .seealso: `PetscGetHostName()`
     38: @*/
     39: PetscErrorCode PetscGetUserName(char name[], size_t nlen)
     40: {
     41:   const char *user;

     43:   PetscFunctionBegin;
     44:   user = getenv("USER");
     45:   if (!user) user = "Unknown";
     46:   PetscCall(PetscStrncpy(name, user, nlen));
     47:   PetscFunctionReturn(PETSC_SUCCESS);
     48: }
     49: #endif