GRASS Programmer's Manual 6.4.1(2011)
home.c
Go to the documentation of this file.
00001 /*
00002  ****************************************************************
00003  * char *
00004  * G_home ()
00005  *
00006  *   returns char pointer to home directory for user
00007  *   dies if can't determine
00008  *
00009  * char *
00010  * G__home()
00011  *
00012  *   returns char pointer to home directory for user
00013  *   NULL if can't determine
00014  *
00015  ***************************************************************/
00016 #include <stdlib.h>
00017 #include <string.h>
00018 #include <grass/gis.h>
00019 #include <grass/glocale.h>
00020 
00021 
00032 char *G_home(void)
00033 {
00034     char *home = G__home();
00035 
00036     if (home)
00037         return home;
00038 
00039     G_fatal_error(_("unable to determine user's home directory"));
00040     return NULL;
00041 }
00042 
00043 char *G__home(void)
00044 {
00045     static char *home = 0;
00046 
00047     if (home)
00048         return home;
00049 
00050 #ifdef __MINGW32__
00051     {
00052         char buf[GPATH_MAX];
00053 
00054         /* TODO: we should probably check if the dir exists */
00055         home = getenv("USERPROFILE");
00056 
00057         if (!home) {
00058             sprintf(buf, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
00059 
00060             if (strlen(buf) >= 0)
00061                 home = G_store(buf);
00062         }
00063 
00064         if (!home)
00065             home = getenv("HOME");
00066     }
00067 #else
00068     home = getenv("HOME");
00069 #endif
00070     return home;
00071 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines