15#include <grass/config.h>
23#include <grass/glocale.h>
25#include "gis_local_proto.h"
52static int G__open(
const char *
element,
const char *
name,
const char *mapset,
58 char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
67 if (*mapset && strcmp(xmapset, mapset) != 0) {
69 _(
"G__open(read): mapset <%s> doesn't match xmapset <%s>"),
89 if ((fd = open(
path, 0)) < 0)
95 if (mode == 1 || mode == 2) {
98 if (strcmp(xmapset, mapset) != 0) {
99 G_warning(_(
"G__open(write): xmapset <%s> != G_mapset() <%s>"),
114 if (mode == 1 || access(
path, 0) != 0) {
119 close(open(
path, O_WRONLY | O_CREAT | O_TRUNC, 0666));
122 if ((fd = open(
path, mode)) < 0)
123 G_warning(_(
"G__open(write): Unable to open '%s': %s"),
path,
197 lseek(fd, 0L, SEEK_END);
225 G_debug(1,
"G_fopen_new(): element = %s, name = %s : NULL",
element,
230 G_debug(2,
"\tfile open: new (mode = w)");
231 return fdopen(fd,
"w");
259 G_debug(2,
"\tfile open: read (mode = r)");
260 return fdopen(fd,
"r");
285 lseek(fd, 0L, SEEK_END);
287 G_debug(2,
"\tfile open: append (mode = a)");
288 return fdopen(fd,
"a");
313 lseek(fd, 0L, SEEK_END);
315 G_debug(2,
"\tfile open: modify (mode = r+)");
316 return fdopen(fd,
"r+");
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
char * G_file_name_tmp(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files in temporary directory (for internal use only)
const char * G_find_file2(const char *element, const char *name, const char *mapset)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch)
void G_warning(const char *msg,...)
Print a warning message to stderr.
FILE * G_fopen_append(const char *element, const char *name)
Open a database file for update (append mode)
int G_open_new(const char *element, const char *name)
Open a new database file.
int G_open_update(const char *element, const char *name)
Open a database file for update.
FILE * G_fopen_modify(const char *element, const char *name)
Open a database file for update (r+ mode)
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
int G_open_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
void G__check_gisinit(void)
Checks to see if GIS engine is initialized.
int G_legal_filename(const char *s)
Check for legal database file name.
const char * G_mapset(void)
Get current mapset name.
int G_make_mapset_object_group_tmp(const char *type)
Create directory for type of objects in the temporary directory.
int G_make_mapset_object_group(const char *type)
Create directory for group of elements of a given type.
int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)