19 #include <grass/gis.h>
20 #include <grass/glocale.h>
24 static int next(
char **replace,
int num_replace)
28 for (i = 0; i < num_replace; i++) {
42 static int G__mkstemp(
char *
template,
int flags,
int mode)
50 char *p = strchr(ptr,
'X');
54 replace[num_replace++] = p;
63 if (!next(replace, num_replace))
66 if (access(
template, F_OK) == 0)
72 fd = open(
template, flags, mode);
107 return G__mkstemp(
template, 0, 0) < 0 ?
NULL :
template;
130 switch (flags & O_ACCMODE) {
132 G_fatal_error(_(
"Attempt to create read-only temporary file"));
138 G_fatal_error(_(
"Unrecognised access mode: %o"), flags & O_ACCMODE);
142 return G__mkstemp(
template, flags | O_CREAT | O_EXCL, mode);
163 const char *fmode = ((flags & O_ACCMODE) == O_RDWR)
164 ? ((flags & O_APPEND) ?
"a+" :
"w+")
165 : ((flags & O_APPEND) ?
"a" :
"w");
166 int fd =
G_mkstemp(
template, flags, mode);
170 return fdopen(fd, fmode);
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
char * G_mktemp(char *template)
Opens a temporary file.
FILE * G_mkstemp_fp(char *template, int flags, int mode)
Returns a file descriptor.
int G_mkstemp(char *template, int flags, int mode)
Returns a file descriptor.