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: int PetscGetUserName(char name[],int nlen)
38: {
40: GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
41: return(0);
42: }
44: #elif defined(PETSC_HAVE_PWD_H)
45: /*@C
46: PetscGetUserName - Returns the name of the user.
48: Not Collective
50: Input Parameter:
51: nlen - length of name
53: Output Parameter:
54: . name - contains user name. Must be long enough to hold the name
56: Level: developer
58: Concepts: user name
60: .seealso: PetscGetHostName()
61: @*/
62: int PetscGetUserName(char name[],int nlen)
63: {
64: struct passwd *pw;
65: int ierr;
68: pw = getpwuid(getuid());
69: if (!pw) {PetscStrncpy(name,"Unknown",nlen);}
70: else {PetscStrncpy(name,pw->pw_name,nlen);}
71: return(0);
72: }
74: #else
76: int PetscGetUserName(char *name,int nlen)
77: {
81: PetscStrncpy(name,"Unknown",nlen);
82: return(0);
83: }
84: #endif /* !PETSC_HAVE_PWD_H */