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 #include <stdlib.h>
00016 
00017 #ifndef __MINGW32__
00018 #include <pwd.h>
00019 #endif
00020 
00021 #include <grass/gis.h>
00022 
00023 
00034 char *G_whoami(void)
00035 {
00036 #ifdef __MINGW32__
00037     char *name =  getenv("USERNAME");
00038     if (name == NULL){
00039         name = "user_name";
00040     }
00041 #else
00042     static char *name= 0;
00043 #ifdef COMMENTED_OUT
00044     char *getlogin();
00045     char *ttyname();
00046 
00047     if (name == NULL)
00048     {
00049         char *x;
00050         x = ttyname(0);
00051         if (x && *x)
00052         {
00053             x = getlogin();
00054             if (x && *x)
00055                 name = G_store (x);
00056         }
00057     }
00058 #endif /* COMMENTED_OUT */
00059 
00060     if (name == NULL)
00061     {
00062         struct passwd *getpwuid();
00063         struct passwd *p;
00064         if((p = getpwuid (getuid())))
00065             name = G_store (p->pw_name);
00066     }
00067     if (name == NULL)
00068         name = G_store ("?");
00069 
00070 #endif
00071     return name;
00072 }

Generated on Fri Nov 21 11:02:18 2008 for GRASS by  doxygen 1.5.1