|
@@ -22,20 +22,18 @@
|
|
|
#include <grass/config.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
-#ifdef HAVE_UNISTD_H
|
|
|
#include <unistd.h>
|
|
|
-#endif
|
|
|
+#include <fcntl.h>
|
|
|
|
|
|
#include <grass/gis.h>
|
|
|
-#include <unistd.h>
|
|
|
-#include <fcntl.h>
|
|
|
+#include <grass/glocale.h>
|
|
|
|
|
|
static int G__open_misc(const char *dir,
|
|
|
const char *element,
|
|
|
const char *name, const char *mapset, int mode)
|
|
|
{
|
|
|
char path[GPATH_MAX];
|
|
|
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *dummy;
|
|
|
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
|
|
|
|
|
|
|
|
|
G__check_gisinit();
|
|
@@ -43,15 +41,18 @@ static int G__open_misc(const char *dir,
|
|
|
/* READ */
|
|
|
if (mode == 0) {
|
|
|
if (G__name_is_fully_qualified(name, xname, xmapset)) {
|
|
|
- if (strcmp(xmapset, mapset) != 0) {
|
|
|
- fprintf(stderr,
|
|
|
- "G__open(r): mapset (%s) doesn't match xmapset (%s)\n",
|
|
|
- mapset, xmapset);
|
|
|
+ if (*mapset && strcmp(xmapset, mapset) != 0) {
|
|
|
+ G_warning(_("G__open_misc(read): mapset <%s> doesn't match xmapset <%s>"),
|
|
|
+ mapset, xmapset);
|
|
|
return -1;
|
|
|
}
|
|
|
name = xname;
|
|
|
+ mapset = xmapset;
|
|
|
}
|
|
|
- if ((dummy = G_find_file2_misc(dir, element, name, mapset)) == NULL)
|
|
|
+ else if (!*mapset)
|
|
|
+ mapset = G_find_file2_misc(dir, element, name, mapset);
|
|
|
+
|
|
|
+ if (!mapset)
|
|
|
return -1;
|
|
|
|
|
|
G__file_name_misc(path, dir, element, name, mapset);
|
|
@@ -60,11 +61,11 @@ static int G__open_misc(const char *dir,
|
|
|
}
|
|
|
/* WRITE */
|
|
|
if (mode == 1 || mode == 2) {
|
|
|
+ mapset = G_mapset();
|
|
|
if (G__name_is_fully_qualified(name, xname, xmapset)) {
|
|
|
- if (strcmp(xmapset, G_mapset()) != 0) {
|
|
|
- fprintf(stderr,
|
|
|
- "G__open(w): xmapset (%s) != G_mapset() (%s)\n",
|
|
|
- xmapset, G_mapset());
|
|
|
+ if (strcmp(xmapset, mapset) != 0) {
|
|
|
+ G_warning(_("G__open_misc(write): xmapset <%s> != G_mapset() <%s>"),
|
|
|
+ xmapset, mapset);
|
|
|
return -1;
|
|
|
}
|
|
|
name = xname;
|
|
@@ -73,7 +74,7 @@ static int G__open_misc(const char *dir,
|
|
|
if (G_legal_filename(name) == -1)
|
|
|
return -1;
|
|
|
|
|
|
- G__file_name_misc(path, dir, element, name, G_mapset());
|
|
|
+ G__file_name_misc(path, dir, element, name, mapset);
|
|
|
if (mode == 1 || access(path, 0) != 0) {
|
|
|
G__make_mapset_element_misc(dir, name);
|
|
|
close(creat(path, 0666));
|