[GRASS-dev] Re: mkdir function

Glynn Clements glynn at gclements.plus.com
Wed Dec 13 16:52:04 EST 2006


Glynn Clements wrote:

> > The following 3 functions are too complicated for me (!)
> > to fix:

> >  lib/gis/mapset_msc.c
> 
> I'm currently testing the attached patch.

I'm surprised I managed to make so many mistakes for such a relatively
small change. I've attached an updated patch; apart from eliminating
the compilation errors, it eliminates the warnings arising from the
addition of G_lstat().

-- 
Glynn Clements <glynn at gclements.plus.com>

-------------- next part --------------
Index: include/gis.h
===================================================================
RCS file: /grassrepository/grass6/include/gis.h,v
retrieving revision 1.36
diff -u -r1.36 gis.h
--- include/gis.h	3 Nov 2006 20:07:09 -0000	1.36
+++ include/gis.h	13 Dec 2006 21:48:44 -0000
@@ -107,6 +107,7 @@
 #define GNAME_MAX 256
 #define GMAPSET_MAX 256
 
+#define GPATH_MAX 4096
 
 /* Macros for type size independent integers                    */
 /* Use these for portability to ensure integers are truly 32bit */
@@ -589,6 +590,9 @@
 };
 
 /*============================== Prototypes ================================*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
 
 /* Since there are so many prototypes for the gis library they are stored */
 /* in the file gisdefs.h */
Index: lib/gis/mapset_msc.c
===================================================================
RCS file: /grassrepository/grass6/lib/gis/mapset_msc.c,v
retrieving revision 1.5
diff -u -r1.5 mapset_msc.c
--- lib/gis/mapset_msc.c	10 Nov 2006 10:02:02 -0000	1.5
+++ lib/gis/mapset_msc.c	13 Dec 2006 21:48:44 -0000
@@ -11,30 +11,20 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
 #include <sys/types.h>
 #include <sys/stat.h>
-
-#ifdef __MINGW32__
-# define mkdir(name, mode) ((mkdir) (name))
-#endif
+#include <grass/gis.h>
+#include <grass/glocale.h>
 
 int G__make_mapset_element (char *p_element)
 {
-    char command[1024];
-    char *path;
+    char path[GPATH_MAX];
     char *p;
-    char *G_mapset();
     char *element;
 
     element = p_element;
     if (*element == 0)
 	    return 0;
-    strcpy (path = command, "mkdir ");
-    while (*path)
-	path++;
 
     G__file_name (p = path, "", "", G_mapset());
     while (*p)
@@ -53,21 +43,10 @@
 	if (*element == '/' || *element == 0)
 	{
 	    *p = 0;
-/* MOD shapiro 16apr91 */
-	    if (access (path, 0) != 0)
-	    {
-		mkdir(path, 0777);
-	    }
-/* end MOD */
 	    if (access (path, 0) != 0)
-	    {
-		system (command);
-	    }
+		G_mkdir(path);
 	    if (access (path, 0) != 0)
-	    {
 		G_fatal_error (_("can't make mapset element %s (%s)"), p_element, path);
-		exit(EXIT_FAILURE);
-	    }
 	    if (*element == 0)
 		return 1;
 	}
@@ -84,12 +63,14 @@
 ****************************************************************/
 int G__mapset_permissions (char *mapset)
 {
-    char path[2000];
+    char path[GPATH_MAX];
     struct stat info;
 
     G__file_name (path,"","",mapset);
 
-    if (stat (path, &info) != 0)
+    if (G_lstat (path, &info) != 0)
+	    return -1;
+    if (!S_ISDIR(info.st_mode))
 	    return -1;
 
 #ifndef __MINGW32__    
@@ -113,12 +94,14 @@
 ****************************************************************/
 int G__mapset_permissions2 ( char * gisdbase, char * location, char *mapset )
 {
-    char path[2000];
+    char path[GPATH_MAX];
     struct stat info;
 
     sprintf ( path, "%s/%s/%s", gisdbase, location, mapset );
 
-    if (stat (path, &info) != 0)
+    if (G_lstat (path, &info) != 0)
+	    return -1;
+    if (!S_ISDIR(info.st_mode))
 	    return -1;
 
 #ifndef __MINGW32__    


More information about the grass-dev mailing list