Date: 2013-07-02T14:39:06+00:00

Actual source code: fuser.c
petsc-3.4.2 2013-07-02

      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/stat.h>
     11: #if defined(PETSC_HAVE_SYS_UTSNAME_H)
     12: #include <sys/utsname.h>
     13: #endif
     14: #if defined(PETSC_HAVE_WINDOWS_H)
     15: #include <windows.h>
     16: #endif
     17: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
     18: #include <sys/systeminfo.h>
     19: #endif
     20: #if defined(PETSC_HAVE_UNISTD_H)
     21: #include <unistd.h>
     22: #endif

     25: #if defined(PETSC_HAVE_GET_USER_NAME)
     28: PetscErrorCode  PetscGetUserName(char name[],size_t nlen)
     29: {
     31:   GetUserName((LPTSTR)name,(LPDWORD)(&nlen));
     32:   return(0);
     33: }

     35: #elif defined(PETSC_HAVE_PWD_H)
     38: /*@C
     39:     PetscGetUserName - Returns the name of the user.

     41:     Not Collective

     43:     Input Parameter:
     44:     nlen - length of name

     46:     Output Parameter:
     47: .   name - contains user name.  Must be long enough to hold the name

     49:     Level: developer

     51:     Concepts: user name

     53: .seealso: PetscGetHostName()
     54: @*/
     55: PetscErrorCode  PetscGetUserName(char name[],size_t nlen)
     56: {
     57:   struct passwd  *pw=0;

     61: #if defined(PETSC_HAVE_GETPWUID)
     62:   pw = getpwuid(getuid());
     63: #endif
     64:   if (!pw) {PetscStrncpy(name,"Unknown",nlen);}
     65:   else     {PetscStrncpy(name,pw->pw_name,nlen);}
     66:   return(0);
     67: }

     69: #else

     73: PetscErrorCode  PetscGetUserName(char *name,size_t nlen)
     74: {

     78:   PetscStrncpy(name,"Unknown",nlen);
     79:   return(0);
     80: }
     81: #endif /* !PETSC_HAVE_PWD_H */