Actual source code: fuser.c
petsc-3.3-p7 2013-05-11
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
29: #if defined(PETSC_HAVE_GET_USER_NAME)
32: PetscErrorCode PetscGetUserName(char name[],size_t nlen)
33: {
35: GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
36: return(0);
37: }
39: #elif defined(PETSC_HAVE_PWD_H)
42: /*@C
43: PetscGetUserName - Returns the name of the user.
45: Not Collective
47: Input Parameter:
48: nlen - length of name
50: Output Parameter:
51: . name - contains user name. Must be long enough to hold the name
53: Level: developer
55: Concepts: user name
57: .seealso: PetscGetHostName()
58: @*/
59: PetscErrorCode PetscGetUserName(char name[],size_t nlen)
60: {
61: struct passwd *pw=0;
65: #if defined(PETSC_HAVE_GETPWUID)
66: pw = getpwuid(getuid());
67: #endif
68: if (!pw) {PetscStrncpy(name,"Unknown",nlen);}
69: else {PetscStrncpy(name,pw->pw_name,nlen);}
70: return(0);
71: }
73: #else
77: PetscErrorCode PetscGetUserName(char *name,size_t nlen)
78: {
82: PetscStrncpy(name,"Unknown",nlen);
83: return(0);
84: }
85: #endif /* !PETSC_HAVE_PWD_H */