25 #include "gis_local_proto.h" 52 static int G__open(
const char *
element,
53 const char *
name,
const char *mapset,
int mode)
62 is_tmp = (element && strncmp(element,
".tmp", 4) == 0);
67 if (*mapset && strcmp(xmapset, mapset) != 0) {
68 G_warning(
_(
"G__open(read): mapset <%s> doesn't match xmapset <%s>"),
88 if ((fd = open(path, 0)) < 0)
89 G_warning(
_(
"G__open(read): Unable to open '%s': %s"),
90 path, strerror(errno));
94 if (mode == 1 || mode == 2) {
97 if (strcmp(xmapset, mapset) != 0) {
98 G_warning(
_(
"G__open(write): xmapset <%s> != G_mapset() <%s>"),
113 if (mode == 1 || access(path, 0) != 0) {
118 close(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666));
121 if ((fd = open(path, mode)) < 0)
122 G_warning(
_(
"G__open(write): Unable to open '%s': %s"),
123 path, strerror(errno));
150 return G__open(element, name,
G_mapset(), 1);
170 int G_open_old(
const char *element,
const char *name,
const char *mapset)
172 return G__open(element, name, mapset, 0);
195 fd = G__open(element, name,
G_mapset(), 2);
197 lseek(fd, 0L, SEEK_END);
224 fd = G__open(element, name,
G_mapset(), 1);
226 G_debug(1,
"G_fopen_new(): element = %s, name = %s : NULL",
231 G_debug(2,
"\tfile open: new (mode = w)");
232 return fdopen(fd,
"w");
253 FILE *
G_fopen_old(
const char *element,
const char *name,
const char *mapset)
257 fd = G__open(element, name, mapset, 0);
259 return (FILE *)
NULL;
261 G_debug(2,
"\tfile open: read (mode = r)");
262 return fdopen(fd,
"r");
284 fd = G__open(element, name,
G_mapset(), 2);
287 lseek(fd, 0L, SEEK_END);
289 G_debug(2,
"\tfile open: append (mode = a)");
290 return fdopen(fd,
"a");
312 fd = G__open(element, name,
G_mapset(), 2);
315 lseek(fd, 0L, SEEK_END);
317 G_debug(2,
"\tfile open: modify (mode = r+)");
318 return fdopen(fd,
"r+");
const char * G_find_file2(const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch) ...
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
int G_make_mapset_object_group_tmp(const char *)
Create directory for type of objects in the temporary directory.
FILE * G_fopen_modify(const char *element, const char *name)
Open a database file for update (r+ mode)
int G_legal_filename(const char *)
Check for legal database file name.
int G_open_update(const char *element, const char *name)
Open a database file for update.
int G_open_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
char * G_file_name_tmp(char *, const char *, const char *, const char *)
Builds full path names to GIS data files in temporary directory (for internal use only) ...
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
const char * G_mapset(void)
Get current mapset name.
int G_open_new(const char *element, const char *name)
Open a new database file.
void G_warning(const char *,...) __attribute__((format(printf
void G__check_gisinit(void)
Checks to see if GIS engine is initialized.
FILE * G_fopen_append(const char *element, const char *name)
Open a database file for update (append mode)
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
int G_debug(int, const char *,...) __attribute__((format(printf
int G_make_mapset_object_group(const char *)
Create directory for group of elements of a given type.