xref: /petsc/src/sys/utils/fuser.c (revision 2205254efee3a00a594e5e2a3a70f74dcb40bc03)
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/types.h>
11 #include <sys/stat.h>
12 #if defined(PETSC_HAVE_STDLIB_H)
13 #include <stdlib.h>
14 #endif
15 #if defined(PETSC_HAVE_SYS_UTSNAME_H)
16 #include <sys/utsname.h>
17 #endif
18 #if defined(PETSC_HAVE_WINDOWS_H)
19 #include <windows.h>
20 #endif
21 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
22 #include <sys/systeminfo.h>
23 #endif
24 #if defined(PETSC_HAVE_UNISTD_H)
25 #include <unistd.h>
26 #endif
27 
28 
29 #if defined(PETSC_HAVE_GET_USER_NAME)
30 #undef __FUNCT__
31 #define __FUNCT__ "PetscGetUserName"
32 PetscErrorCode  PetscGetUserName(char name[],size_t nlen)
33 {
34   PetscFunctionBegin;
35   GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
36   PetscFunctionReturn(0);
37 }
38 
39 #elif defined(PETSC_HAVE_PWD_H)
40 #undef __FUNCT__
41 #define __FUNCT__ "PetscGetUserName"
42 /*@C
43     PetscGetUserName - Returns the name of the user.
44 
45     Not Collective
46 
47     Input Parameter:
48     nlen - length of name
49 
50     Output Parameter:
51 .   name - contains user name.  Must be long enough to hold the name
52 
53     Level: developer
54 
55     Concepts: user name
56 
57 .seealso: PetscGetHostName()
58 @*/
59 PetscErrorCode  PetscGetUserName(char name[],size_t nlen)
60 {
61   struct passwd  *pw=0;
62   PetscErrorCode ierr;
63 
64   PetscFunctionBegin;
65 #if defined(PETSC_HAVE_GETPWUID)
66   pw = getpwuid(getuid());
67 #endif
68   if (!pw) {ierr = PetscStrncpy(name,"Unknown",nlen);CHKERRQ(ierr);}
69   else     {ierr = PetscStrncpy(name,pw->pw_name,nlen);CHKERRQ(ierr);}
70   PetscFunctionReturn(0);
71 }
72 
73 #else
74 
75 #undef __FUNCT__
76 #define __FUNCT__ "PetscGetUserName"
77 PetscErrorCode  PetscGetUserName(char *name,size_t nlen)
78 {
79   PetscErrorCode ierr;
80 
81   PetscFunctionBegin;
82   ierr = PetscStrncpy(name,"Unknown",nlen);CHKERRQ(ierr);
83   PetscFunctionReturn(0);
84 }
85 #endif /* !PETSC_HAVE_PWD_H */
86 
87