xref: /petsc/src/sys/utils/fuser.c (revision 45082d6442ec9e1b1f93dc9865927cf3ea3aa1d4)
1 
2 /*
3       Code for manipulating files.
4 */
5 #include <petscsys.h>
6 #if defined(PETSC_HAVE_PWD_H)
7 #include <pwd.h>
8 #endif
9 #include <ctype.h>
10 #include <sys/stat.h>
11 #if defined(PETSC_HAVE_SYS_UTSNAME_H)
12 #include <sys/utsname.h>
13 #endif
14 #if defined(PETSC_HAVE_WINDOWS_H)
15 #include <windows.h>
16 #endif
17 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
18 #include <sys/systeminfo.h>
19 #endif
20 #if defined(PETSC_HAVE_UNISTD_H)
21 #include <unistd.h>
22 #endif
23 
24 
25 #if defined(PETSC_HAVE_GET_USER_NAME)
26 #undef __FUNCT__
27 #define __FUNCT__ "PetscGetUserName"
28 PetscErrorCode  PetscGetUserName(char name[],size_t nlen)
29 {
30   PetscFunctionBegin;
31   GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
32   PetscFunctionReturn(0);
33 }
34 
35 #else
36 #undef __FUNCT__
37 #define __FUNCT__ "PetscGetUserName"
38 /*@C
39     PetscGetUserName - Returns the name of the user.
40 
41     Not Collective
42 
43     Input Parameter:
44     nlen - length of name
45 
46     Output Parameter:
47 .   name - contains user name.  Must be long enough to hold the name
48 
49     Level: developer
50 
51     Concepts: user name
52 
53 .seealso: PetscGetHostName()
54 @*/
55 PetscErrorCode  PetscGetUserName(char name[],size_t nlen)
56 {
57   const char     *user;
58   PetscErrorCode ierr;
59 
60   PetscFunctionBegin;
61   user = getenv("USER");
62   if (!user) user = "Unknown";
63   ierr = PetscStrncpy(name,user,nlen);CHKERRQ(ierr);
64   PetscFunctionReturn(0);
65 }
66 #endif
67