From 514d0e31724a6943dfb22351b2c92cbd88da5391 Mon Sep 17 00:00:00 2001 From: Andrej Kacian Date: Mon, 22 Jun 2015 21:14:39 +0200 Subject: [PATCH] Use g_mkstemp() instead of mkstemp(). Also, removed our implementation of mkstemp() for Windows. Glib has us covered. --- src/common/utils.c | 42 ++----------------------------- src/plugins/mailmbox/mailmbox.c | 2 +- src/plugins/mailmbox/mmapstring.c | 3 ++- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/src/common/utils.c b/src/common/utils.c index 17e839d1f..51bc5e1e8 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -218,37 +218,6 @@ int g_open(const gchar *filename, int flags, int mode) #endif /* G_OS_UNIX */ -#ifdef G_OS_WIN32 -gint mkstemp_name(gchar *template, gchar **name_used) -{ - static gulong count=0; /* W32-_mktemp only supports up to 27 - tempfiles... */ - int tmpfd; - - *name_used = g_strdup_printf("%s.%ld",_mktemp(template),count++); - tmpfd = g_open (*name_used, (O_CREAT | O_RDWR | O_BINARY), - (S_IRUSR | S_IWUSR)); - - tempfiles=g_slist_append(tempfiles, g_strdup(*name_used)); - if (tmpfd<0) { - perror(g_strdup_printf("cant create %s",*name_used)); - return -1; - } - else - return tmpfd; -} -#endif /* G_OS_WIN32 */ - -#ifdef G_OS_WIN32 -gint mkstemp(gchar *template) -{ - gchar *dummyname; - gint res = mkstemp_name(template, &dummyname); - g_free(dummyname); - return res; -} -#endif /* G_OS_WIN32 */ - GSList *slist_copy_deep(GSList *list, GCopyFunc func) { #if GLIB_CHECK_VERSION(2, 34, 0) @@ -3093,7 +3062,7 @@ FILE *my_tmpfile(void) memcpy(fname + tmplen + 1, progname, proglen); memcpy(fname + tmplen + 1 + proglen, suffix, sizeof(suffix)); - fd = mkstemp(fname); + fd = g_mkstemp(fname); if (fd < 0) return tmpfile(); @@ -3124,17 +3093,10 @@ FILE *my_tmpfile(void) FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename) { int fd; -#ifdef G_OS_WIN32 - char *template = g_strdup_printf ("%s%cclaws.XXXXXX", - dir, G_DIR_SEPARATOR); - fd = mkstemp_name(template, filename); - g_free(template); -#else *filename = g_strdup_printf("%s%cclaws.XXXXXX", dir, G_DIR_SEPARATOR); - fd = mkstemp(*filename); + fd = g_mkstemp(*filename); if (fd < 0) return NULL; -#endif return fdopen(fd, "w+"); } diff --git a/src/plugins/mailmbox/mailmbox.c b/src/plugins/mailmbox/mailmbox.c index 3c4ada57d..1d0578d89 100644 --- a/src/plugins/mailmbox/mailmbox.c +++ b/src/plugins/mailmbox/mailmbox.c @@ -1258,7 +1258,7 @@ int claws_mailmbox_expunge_no_lock(struct claws_mailmbox_folder * folder) } snprintf(tmpfile, PATH_MAX, "%sXXXXXX", folder->mb_filename); - dest_fd = mkstemp(tmpfile); + dest_fd = g_mkstemp(tmpfile); if (dest_fd < 0) { res = MAILMBOX_ERROR_FILE; diff --git a/src/plugins/mailmbox/mmapstring.c b/src/plugins/mailmbox/mmapstring.c index a7baa1727..2bf3582f5 100644 --- a/src/plugins/mailmbox/mmapstring.c +++ b/src/plugins/mailmbox/mmapstring.c @@ -37,6 +37,7 @@ #include "chash.h" +#include #include #include #include @@ -188,7 +189,7 @@ static MMAPString * mmap_string_realloc_file(MMAPString * string) strcat(tmpfilename, tmpdir); strcat(tmpfilename, "/libetpan-mmapstring-XXXXXX"); - fd = mkstemp(tmpfilename); + fd = g_mkstemp(tmpfilename); if (fd == -1) return NULL; -- 2.25.1