#include "file_util.h"
-#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6)
-#include <glib/gstdio.h> /* available since GLib 2.6 only! */
-
-/* GLib2.6 or above, using new wrapper functions */
-#define eth_mkstemp g_mkstemp
-#else
-#define eth_mkstemp mkstemp
-#endif
-
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#include "tempfile.h"
+#include "mkstemp.h"
static const char *
setup_tmpdir(const char *dir)
return dir;
}
else {
- newdir = g_malloc(len + 2);
- strcpy(newdir, dir);
- strcat(newdir, G_DIR_SEPARATOR_S);
+ newdir = g_strdup_printf("%s%s", dir, G_DIR_SEPARATOR_S);
return newdir;
}
}
int old_umask;
int tmp_fd;
+ g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
if (namebuflen < namelen) {
- /* Stick in a truncated name, so that if this error is
+ /* Stick with the truncated name, so that if this error is
reported with the file name, you at least get
something. */
- g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
errno = ENAMETOOLONG;
return -1;
}
- strcpy(namebuf, dir);
- strcat(namebuf, pfx);
- strcat(namebuf, suffix);
/* The Single UNIX Specification doesn't say that "mkstemp()"
creates the temporary file with mode rw-------, so we
permissions, attempt to create the file, and then put
the umask back. */
old_umask = umask(0077);
- tmp_fd = eth_mkstemp(namebuf);
+ tmp_fd = mkstemp(namebuf);
umask(old_umask);
return tmp_fd;
}