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