Actual source code: fuser.c

  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"


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

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

 47:     Not Collective

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

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

 55:     Level: developer

 57:     Concepts: user name

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

 67:   pw = getpwuid(getuid());
 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 */