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 "gis.h"
00018 #include "glocale.h"
00019 
00020 
00031 char *
00032 G_home ()
00033 {
00034     char *home;
00035     
00046 char *G_home();
00047 
00048     if ((home = G__home()))
00049         return home;
00050     
00051     G_fatal_error (_("unable to determine user's home directory"));
00052     exit(-1);
00053 }
00054 
00055 char *
00056 G__home ()
00057 {
00058     static char *home = 0;
00059     char buf[1024];
00060     FILE *fd,*G_popen();
00061 
00062 /* first call must get home
00063 * execute the command "cd; pwd" and read the
00064 * output to get the home directory
00065 */
00066     if (!home)
00067     {
00068         if((fd = G_popen ("cd; pwd","r")))
00069         {
00070             if (fscanf (fd,"%s", buf) == 1)
00071                 home = G_store (buf);
00072             G_pclose (fd);
00073         }
00074     }
00075 
00076     return home;
00077 }

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