Actual source code: fuser.c

  1: /*
  2:       Code for manipulating files.
  3: */
 4:  #include petsc.h
 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: #include "petscfix.h"


 30: #if defined(PETSC_HAVE_GET_USER_NAME)
 33: PetscErrorCode PetscGetUserName(char name[],size_t nlen)
 34: {
 36:   GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
 37:   return(0);
 38: }

 40: #elif defined(PETSC_HAVE_PWD_H)
 43: /*@C
 44:     PetscGetUserName - Returns the name of the user.

 46:     Not Collective

 48:     Input Parameter:
 49:     nlen - length of name

 51:     Output Parameter:
 52: .   name - contains user name.  Must be long enough to hold the name

 54:     Level: developer

 56:     Concepts: user name

 58: .seealso: PetscGetHostName()
 59: @*/
 60: PetscErrorCode PetscGetUserName(char name[],size_t nlen)
 61: {
 62:   struct passwd *pw;

 66:   pw = getpwuid(getuid());
 67:   if (!pw) {PetscStrncpy(name,"Unknown",nlen);}
 68:   else     {PetscStrncpy(name,pw->pw_name,nlen);}
 69:   return(0);
 70: }

 72: #else

 76: PetscErrorCode PetscGetUserName(char *name,size_t nlen)
 77: {

 81:   PetscStrncpy(name,"Unknown",nlen);
 82:   return(0);
 83: }
 84: #endif /* !PETSC_HAVE_PWD_H */