mapset_msc.c

Go to the documentation of this file.
00001 /*********************************************************
00002  * G__make_mapset_element (element)
00003  *     char *element           element to be created in mapset
00004  *
00005  * make the specified element in the current mapset
00006  * will check for the existence of the element and
00007  * do nothing if it is found so this routine
00008  * can be called even if the element already exists
00009  ********************************************************/
00010 
00011 #include <string.h>
00012 #include <unistd.h>
00013 #include <stdlib.h>
00014 #include <grass/gis.h>
00015 #include <grass/glocale.h>
00016 
00017 #include <sys/types.h>
00018 #include <sys/stat.h>
00019 
00020 #ifdef __MINGW32__
00021 # define mkdir(name, mode) ((mkdir) (name))
00022 #endif
00023 
00024 int G__make_mapset_element (char *p_element)
00025 {
00026     char command[1024];
00027     char *path;
00028     char *p;
00029     char *G_mapset();
00030     char *element;
00031 
00032     element = p_element;
00033     if (*element == 0)
00034             return 0;
00035     strcpy (path = command, "mkdir ");
00036     while (*path)
00037         path++;
00038 
00039     G__file_name (p = path, "", "", G_mapset());
00040     while (*p)
00041         p++;
00042 /* add trailing slash if missing */
00043     --p;
00044     if (*p++ != '/')
00045     {
00046         *p++ = '/' ;
00047         *p = 0;
00048     }
00049 
00050 /* now append element, one directory at a time, to path */
00051     while (1)
00052     {
00053         if (*element == '/' || *element == 0)
00054         {
00055             *p = 0;
00056 /* MOD shapiro 16apr91 */
00057             if (access (path, 0) != 0)
00058             {
00059                 mkdir(path, 0777);
00060             }
00061 /* end MOD */
00062             if (access (path, 0) != 0)
00063             {
00064                 system (command);
00065             }
00066             if (access (path, 0) != 0)
00067             {
00068                 char err[1024];
00069                 sprintf (err, _("can't make mapset element %s (%s)"), p_element, path);
00070                 G_fatal_error (err);
00071                 exit(1);
00072             }
00073             if (*element == 0)
00074                 return 1;
00075         }
00076         *p++ = *element++;
00077     }
00078 }
00079 
00080 /****************************************************************
00081 * G__mapset_permissions (mapset)
00082 *
00083 * returns: 1 mapset exists, and user has permission
00084 *          0 mapset exists, BUT user denied permission
00085 *         -1 mapset does not exist
00086 ****************************************************************/
00087 int G__mapset_permissions (char *mapset)
00088 {
00089     char path[2000];
00090     struct stat info;
00091 
00092     G__file_name (path,"","",mapset);
00093 
00094     if (stat (path, &info) != 0)
00095             return -1;
00096 
00097 #ifndef __MINGW32__    
00098     if (info.st_uid != getuid())
00099             return 0;
00100     if (info.st_uid != geteuid())
00101             return 0;
00102 #endif
00103     
00104     return 1;
00105 }
00106 
00107 /****************************************************************
00108 * G__mapset_permissions2 ( gisdbase, location, mapset)
00109 *
00110 * mapset_path is full path to mapset directory
00111 *
00112 * returns: 1 mapset exists, and user has permission
00113 *          0 mapset exists, BUT user denied permission
00114 *         -1 mapset does not exist
00115 ****************************************************************/
00116 int G__mapset_permissions2 ( char * gisdbase, char * location, char *mapset )
00117 {
00118     char path[2000];
00119     struct stat info;
00120 
00121     sprintf ( path, "%s/%s/%s", gisdbase, location, mapset );
00122 
00123     if (stat (path, &info) != 0)
00124             return -1;
00125 
00126 #ifndef __MINGW32__    
00127     if (info.st_uid != getuid())
00128             return 0;
00129     if (info.st_uid != geteuid())
00130             return 0;
00131 #endif
00132     
00133     return 1;
00134 }
00135 

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