[GRASS-SVN] r60149 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 7 11:14:59 PDT 2014
Author: mmetz
Date: 2014-05-07 11:14:59 -0700 (Wed, 07 May 2014)
New Revision: 60149
Modified:
grass/trunk/lib/gis/open.c
grass/trunk/lib/gis/open_misc.c
Log:
libgis: do not open non-existing files; add warning when opening a file failed
Modified: grass/trunk/lib/gis/open.c
===================================================================
--- grass/trunk/lib/gis/open.c 2014-05-07 18:13:21 UTC (rev 60148)
+++ grass/trunk/lib/gis/open.c 2014-05-07 18:14:59 UTC (rev 60149)
@@ -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/trunk/lib/gis/open_misc.c
===================================================================
--- grass/trunk/lib/gis/open_misc.c 2014-05-07 18:13:21 UTC (rev 60148)
+++ grass/trunk/lib/gis/open_misc.c 2014-05-07 18:14:59 UTC (rev 60149)
@@ -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