Date: 2026-07-30T21:14:27+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: /*@C
     10:   PetscGetUserName - Get the login name of the user running the program on the current MPI process

     12:   Not Collective

     14:   Input Parameter:
     15: . nlen - length of the `name` buffer

     17:   Output Parameter:
     18: . name - on output, holds the user name (null-terminated)

     20:   Level: developer

     22: .seealso: `PetscGetHostName()`, `PetscGetProgramName()`
     23: @*/
     24: #if defined(PETSC_HAVE_GET_USER_NAME)
     25: PetscErrorCode PetscGetUserName(char name[], size_t nlen)
     26: {
     27:   PetscFunctionBegin;
     28:   GetUserName((LPTSTR)name, (LPDWORD)(&nlen));
     29:   PetscFunctionReturn(PETSC_SUCCESS);
     30: }

     32: #else

     34: PetscErrorCode PetscGetUserName(char name[], size_t nlen)
     35: {
     36:   const char *user;

     38:   PetscFunctionBegin;
     39:   user = getenv("USER");
     40:   if (!user) user = "Unknown";
     41:   PetscCall(PetscStrncpy(name, user, nlen));
     42:   PetscFunctionReturn(PETSC_SUCCESS);
     43: }
     44: #endif