15 #include <grass/config.h>
21 #include <grass/gis.h>
22 #include <grass/glocale.h>
49 static int G__open(
const char *element,
50 const char *
name,
const char *mapset,
int mode)
53 char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
61 if (*mapset && strcmp(xmapset, mapset) != 0) {
62 G_warning(_(
"G__open(read): mapset <%s> doesn't match xmapset <%s>"),
69 else if (!mapset || !*mapset)
80 if (mode == 1 || mode == 2) {
83 if (strcmp(xmapset, mapset) != 0) {
84 G_warning(_(
"G__open(write): xmapset <%s> != G_mapset() <%s>"),
96 if (mode == 1 || access(path, 0) != 0) {
98 close(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666));
101 return open(path, mode);
127 return G__open(element, name,
G_mapset(), 1);
147 int G_open_old(
const char *element,
const char *name,
const char *mapset)
149 return G__open(element, name, mapset, 0);
172 fd = G__open(element, name,
G_mapset(), 2);
174 lseek(fd, 0L, SEEK_END);
201 fd = G__open(element, name,
G_mapset(), 1);
205 return fdopen(fd,
"w");
226 FILE *
G_fopen_old(
const char *element,
const char *name,
const char *mapset)
230 fd = G__open(element, name, mapset, 0);
234 return fdopen(fd,
"r");
256 fd = G__open(element, name,
G_mapset(), 2);
259 lseek(fd, 0L, SEEK_END);
261 return fdopen(fd,
"a");
283 fd = G__open(element, name,
G_mapset(), 2);
286 lseek(fd, 0L, SEEK_END);
288 return fdopen(fd,
"r+");