whoami.c

Go to the documentation of this file.
00001 /******************************************************************
00002  *
00003  *  char *
00004  *  G_whoami()
00005  *
00006  *  Returns a string containing the name of the current user.
00007  *
00008  *  Try getlogin() first, then go to paswd file
00009  *  However, some masscomp getlogin() fails in ucb universe
00010  *  This is because the ttyname(0) rotuine fails in ucb universe.
00011  *  So check for this too.
00012  *
00013  *****************************************************************/
00014 #include <unistd.h>
00015 
00016 #ifndef __MINGW32__
00017 #include <pwd.h>
00018 #endif
00019 
00020 #include "gis.h"
00021 
00022 
00033 char *G_whoami(void)
00034 {
00035 #ifdef __MINGW32__
00036     static char *name = "mingw_user_name";
00037 #else
00038     static char *name= 0;
00039 #ifdef COMMENTED_OUT
00040     char *getlogin();
00041     char *ttyname();
00042 
00043     if (name == NULL)
00044     {
00045         char *x;
00046         x = ttyname(0);
00047         if (x && *x)
00048         {
00049             x = getlogin();
00050             if (x && *x)
00051                 name = G_store (x);
00052         }
00053     }
00054 #endif /* COMMENTED_OUT */
00055 
00056     if (name == NULL)
00057     {
00058         struct passwd *getpwuid();
00059         struct passwd *p;
00060         if((p = getpwuid (getuid())))
00061             name = G_store (p->pw_name);
00062     }
00063     if (name == NULL)
00064         name = G_store ("?");
00065 
00066 #endif
00067     return name;
00068 }

Generated on Mon Jan 1 19:49:26 2007 for GRASS by  doxygen 1.5.1