20#include <grass/glocale.h>
24static int next(
char **replace,
int num_replace)
28 for (i = 0; i < num_replace; i++) {
42static 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;
131 switch (flags & O_ACCMODE) {
133 G_fatal_error(_(
"Attempt to create read-only temporary file"));
139 G_fatal_error(_(
"Unrecognised access mode: %o"), flags & O_ACCMODE);
143 return G__mkstemp(
template, flags | O_CREAT | O_EXCL, mode);
165 const char *fmode = ((flags & O_ACCMODE) == O_RDWR)
166 ? ((flags & O_APPEND) ?
"a+" :
"w+")
167 : ((flags & O_APPEND) ?
"a" :
"w");
168 int fd =
G_mkstemp(
template, flags, mode);
172 return fdopen(fd, fmode);
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
FILE * G_mkstemp_fp(char *template, int flags, int mode)
Returns a file descriptor.
char * G_mktemp(char *template)
Opens a temporary file.
int G_mkstemp(char *template, int flags, int mode)
Returns a file descriptor.