location.c

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  *   char *
00004  *   G_location_path()
00005  *
00006  *   returns pointer to the full path name to the current location
00007  *
00008  *   note:
00009  *      exits with message if path not accessible to user
00010  **********************************************************************
00011  *
00012  *   char *
00013  *   G_location()
00014  *
00015  *   returns:    pointer to string containing the one word location
00016  *               name.
00017  **********************************************************************/
00018 
00019 #include <stdio.h>
00020 #include <string.h>
00021 #include <unistd.h>
00022 #include <sys/types.h>
00023 #include <grass/gis.h>
00024 #include <grass/glocale.h>
00025 
00026 
00040 char *
00041 G_location_path()
00042 {
00043     char *location;
00044 
00045     location = G__location_path();
00046     if(access(location,0) != 0) 
00047     {
00048         perror("access");
00049         G_fatal_error (_("LOCATION << %s >> not available"), location);
00050     }
00051 
00052     return location;
00053 }
00054 
00055 
00068 char *
00069 G_location()
00070 {
00071     return G_getenv ("LOCATION_NAME");
00072 }
00073 
00074 char *
00075 G__location_path()
00076 {
00077     char *location = 0;
00078     char *base;
00079     char *name;
00080 
00081     name      = G_location();
00082     base      = G_gisdbase();
00083     location  = G_malloc (strlen (base) + strlen (name) + 2);
00084 
00085     /* Forward slash is supported on Windows and back slash can cause 
00086      * problems in scripts */
00087 
00088 /*#ifdef __MINGW32__
00089      sprintf (location, "%s\\%s", base, name);
00090  #else */
00091     sprintf (location, "%s/%s", base, name);
00092 /*#endif */
00093 
00094     return location;
00095 }

Generated on Wed Dec 19 14:59:06 2007 for GRASS by  doxygen 1.5.4