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