[GRASS-SVN] r61437 - in grass/branches/releasebranch_7_0: . lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 28 15:20:50 PDT 2014


Author: neteler
Date: 2014-07-28 15:20:49 -0700 (Mon, 28 Jul 2014)
New Revision: 61437

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/lib/gis/open.c
   grass/branches/releasebranch_7_0/lib/gis/open_misc.c
Log:
libgis: do not open non-existing files; add warning when opening a file failed (trunk, r60149)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:59505,59646,60100-60101,60203-60204,60215,60219,60278,60376,60610,60625,60807,60835,60936-60937,61159-61160,61165,61275,61288,61290,61292,61294,61301
   + /grass/trunk:59505,59646,60100-60101,60149,60203-60204,60215,60219,60278,60376,60610,60625,60807,60835,60936-60937,61159-61160,61165,61275,61288,61290,61292,61294,61301

Modified: grass/branches/releasebranch_7_0/lib/gis/open.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/open.c	2014-07-28 22:17:21 UTC (rev 61436)
+++ grass/branches/releasebranch_7_0/lib/gis/open.c	2014-07-28 22:20:49 UTC (rev 61437)
@@ -13,6 +13,7 @@
  */
 
 #include <grass/config.h>
+#include <errno.h>
 #include <string.h>
 
 #include <unistd.h>
@@ -49,6 +50,7 @@
 static int G__open(const char *element,
 		   const char *name, const char *mapset, int mode)
 {
+    int fd;
     char path[GPATH_MAX];
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
 
@@ -66,15 +68,18 @@
 	    name = xname;
 	    mapset = xmapset;
 	}
-	else if (!mapset || !*mapset)
-	    mapset = G_find_file2(element, name, mapset);
 
+	mapset = G_find_file2(element, name, mapset);
+
 	if (!mapset)
 	    return -1;
 
 	G_file_name(path, element, name, mapset);
 
-	return open(path, 0);
+	if ((fd = open(path, 0)) < 0)
+	    G_warning(_("G__open(read): Unable to open '%s': %s"),
+	              path, strerror(errno));
+	return fd;
     }
     /* WRITE */
     if (mode == 1 || mode == 2) {
@@ -98,7 +103,10 @@
 	    close(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666));
 	}
 
-	return open(path, mode);
+	if ((fd = open(path, mode)) < 0)
+	    G_warning(_("G__open(write): Unable to open '%s': %s"),
+	              path, strerror(errno));
+	return fd;
     }
     return -1;
 }

Modified: grass/branches/releasebranch_7_0/lib/gis/open_misc.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/open_misc.c	2014-07-28 22:17:21 UTC (rev 61436)
+++ grass/branches/releasebranch_7_0/lib/gis/open_misc.c	2014-07-28 22:20:49 UTC (rev 61437)
@@ -20,6 +20,7 @@
  *****************************************************************************/
 
 #include <grass/config.h>
+#include <errno.h>
 #include <string.h>
 
 #include <unistd.h>
@@ -32,6 +33,7 @@
 			const char *element,
 			const char *name, const char *mapset, int mode)
 {
+    int fd;
     char path[GPATH_MAX];
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
 
@@ -49,15 +51,18 @@
 	    name = xname;
 	    mapset = xmapset;
 	}
-	else if (!*mapset)
-    	    mapset = G_find_file2_misc(dir, element, name, mapset);
 
+	mapset = G_find_file2_misc(dir, element, name, mapset);
+
 	if (!mapset)
 	    return -1;
 
 	G_file_name_misc(path, dir, element, name, mapset);
 
-	return open(path, 0);
+	if ((fd = open(path, 0)) < 0)
+	    G_warning("G__open_misc(read): Unable to open '%s': %s",
+	              path, strerror(errno));
+	return fd;
     }
     /* WRITE */
     if (mode == 1 || mode == 2) {
@@ -80,7 +85,10 @@
 	    close(creat(path, 0666));
 	}
 
-	return open(path, mode);
+	if ((fd = open(path, mode)) < 0)
+	    G_warning("G__open_misc(write): Unable to open '%s': %s",
+	              path, strerror(errno));
+	return fd;
     }
     return -1;
 }



More information about the grass-commit mailing list