xref: /petsc/src/sys/utils/fuser.c (revision a69119a591a03a9d906b29c0a4e9802e4d7c9795)
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 PetscErrorCode PetscGetUserName(char name[], size_t nlen) {
12   PetscFunctionBegin;
13   GetUserName((LPTSTR)name, (LPDWORD)(&nlen));
14   PetscFunctionReturn(0);
15 }
16 
17 #else
18 /*@C
19     PetscGetUserName - Returns the name of the user.
20 
21     Not Collective
22 
23     Input Parameter:
24     nlen - length of name
25 
26     Output Parameter:
27 .   name - contains user name.  Must be long enough to hold the name
28 
29     Level: developer
30 
31 .seealso: `PetscGetHostName()`
32 @*/
33 PetscErrorCode PetscGetUserName(char name[], size_t nlen) {
34   const char *user;
35 
36   PetscFunctionBegin;
37   user = getenv("USER");
38   if (!user) user = "Unknown";
39   PetscCall(PetscStrncpy(name, user, nlen));
40   PetscFunctionReturn(0);
41 }
42 #endif
43