00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <stdlib.h>
00017 #include <string.h>
00018 #include <grass/gis.h>
00019 #include <grass/glocale.h>
00020
00021
00032 char *
00033 G_home ()
00034 {
00035 char *home;
00036
00047 char *G_home();
00048
00049 if ((home = G__home()))
00050 return home;
00051
00052 G_fatal_error (_("unable to determine user's home directory"));
00053 exit(-1);
00054 }
00055
00056 char *
00057 G__home ()
00058 {
00059 static char *home = 0;
00060 char buf[1024];
00061
00062 if (home)
00063 return home;
00064
00065 #ifdef __MINGW32__
00066 {
00067
00068 home = getenv ( "USERPROFILE" ) ;
00069
00070 if ( !home )
00071 {
00072 sprintf ( buf, "%s%s", getenv ( "HOMEDRIVE" ),
00073 getenv ( "HOMEPATH" ) );
00074
00075 if ( strlen(buf) >= 0 )
00076 home = G_store ( buf );
00077 }
00078
00079 if ( !home )
00080 home = getenv ( "HOME" ) ;
00081 }
00082 #else
00083 {
00084 FILE *fd,*G_popen();
00085
00086
00087
00088
00089
00090 if((fd = G_popen ("cd; pwd","r")))
00091 {
00092 if (fscanf (fd,"%s", buf) == 1)
00093 home = G_store (buf);
00094 G_pclose (fd);
00095 }
00096 }
00097 #endif
00098 G_debug (2, "G__home home = %s", home );
00099 return home;
00100 }