Actual source code: fuser.c
1: /*$Id: fuser.c,v 1.31 2001/03/23 23:20:45 balay Exp $*/
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(PARCH_win32)
17: #include <sys/utsname.h>
18: #endif
19: #if defined(PARCH_win32)
20: #include <windows.h>
21: #include <io.h>
22: #include <direct.h>
23: #endif
24: #if defined (PARCH_win32_gnu)
25: #include <windows.h>
26: #endif
27: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
28: #include <sys/systeminfo.h>
29: #endif
30: #if defined(PETSC_HAVE_UNISTD_H)
31: #include <unistd.h>
32: #endif
33: #include "petscfix.h"
36: #if defined(PETSC_HAVE_GET_USER_NAME)
37: #undef __FUNCT__
39: int PetscGetUserName(char name[],int nlen)
40: {
42: GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
43: return(0);
44: }
46: #elif defined(PETSC_HAVE_PWD_H)
47: #undef __FUNCT__
49: /*@C
50: PetscGetUserName - Returns the name of the user.
52: Not Collective
54: Input Parameter:
55: nlen - length of name
57: Output Parameter:
58: . name - contains user name. Must be long enough to hold the name
60: Level: developer
62: Concepts: user name
64: .seealso: PetscGetHostName()
65: @*/
66: int PetscGetUserName(char name[],int nlen)
67: {
68: struct passwd *pw;
69: int ierr;
72: pw = getpwuid(getuid());
73: if (!pw) {PetscStrncpy(name,"Unknown",nlen);}
74: else {PetscStrncpy(name,pw->pw_name,nlen);}
75: return(0);
76: }
78: #else
80: #undef __FUNCT__
82: int PetscGetUserName(char *name,int nlen)
83: {
87: PetscStrncpy(name,"Unknown",nlen);
88: return(0);
89: }
90: #endif /* !PETSC_HAVE_PWD_H */