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 "gis.h"
00015 #include "glocale.h"
00016 
00017 #include <sys/types.h>
00018 #include <sys/stat.h>
00019 
00020 int G__make_mapset_element (char *p_element)
00021 {
00022     char command[1024];
00023     char *path;
00024     char *p;
00025     char *G_mapset();
00026     char *element;
00027 
00028     element = p_element;
00029     if (*element == 0)
00030             return 0;
00031     strcpy (path = command, "mkdir ");
00032     while (*path)
00033         path++;
00034 
00035     G__file_name (p = path, "", "", G_mapset());
00036     while (*p)
00037         p++;
00038 /* add trailing slash if missing */
00039     --p;
00040     if (*p++ != '/')
00041     {
00042         *p++ = '/' ;
00043         *p = 0;
00044     }
00045 
00046 /* now append element, one directory at a time, to path */
00047     while (1)
00048     {
00049         if (*element == '/' || *element == 0)
00050         {
00051             *p = 0;
00052 /* MOD shapiro 16apr91 */
00053             if (access (path, 0) != 0)
00054             {
00055 #ifdef __MINGW32__
00056                 mkdir(path);
00057 #else                
00058                 mkdir(path,0777);
00059 #endif
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 Mon Jan 1 19:49:25 2007 for GRASS by  doxygen 1.5.1