X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0509728c8a506f287fa3483d8e8ffaf8fb66d41d..b8a6686de69dbcedbf60f5880ba86994597f2c7f:/sbr/m_mktemp.c diff --git a/sbr/m_mktemp.c b/sbr/m_mktemp.c index 9a28b48a..61a32f68 100644 --- a/sbr/m_mktemp.c +++ b/sbr/m_mktemp.c @@ -5,9 +5,9 @@ * complete copyright information. */ -#include -#include -#include +#include "h/mh.h" +#include "h/utils.h" +#include "h/signals.h" #include "m_maildir.h" #include "m_mktemp.h" @@ -51,7 +51,6 @@ m_mktemp ( { static char tmpfil[BUFSIZ]; int fd = -1; - int keep_open = 0; mode_t oldmode = umask(077); if (pfx_in == NULL) { @@ -69,9 +68,10 @@ m_mktemp ( register_for_removal(tmpfil); + bool keep_open = false; if (fd_ret != NULL) { *fd_ret = fd; - keep_open = 1; + keep_open = true; } if (fp_ret != NULL) { FILE *fp = fdopen(fd, "w+"); @@ -84,7 +84,7 @@ m_mktemp ( return NULL; } *fp_ret = fp; - keep_open = 1; + keep_open = true; } if (!keep_open) { close(fd); @@ -151,7 +151,6 @@ m_mktemps( { char *tmpfil; int fd = -1; - int keep_open = 0; mode_t oldmode = umask(077); if (suffix == NULL) { @@ -202,9 +201,10 @@ m_mktemps( register_for_removal(tmpfil); + bool keep_open = false; if (fd_ret != NULL) { *fd_ret = fd; - keep_open = 1; + keep_open = true; } if (fp_ret != NULL) { FILE *fp = fdopen(fd, "w+"); @@ -218,7 +218,7 @@ m_mktemps( return NULL; } *fp_ret = fp; - keep_open = 1; + keep_open = true; } if (!keep_open) { close(fd); @@ -256,9 +256,10 @@ static svector_t exit_filelist = NULL; * Register a file for removal at program termination. */ static void -register_for_removal(const char *pathname) { +register_for_removal(const char *pathname) +{ if (exit_filelist == NULL) exit_filelist = svector_create(20); - (void) svector_push_back(exit_filelist, add(pathname, NULL)); + (void) svector_push_back(exit_filelist, mh_xstrdup(pathname)); } /* @@ -280,7 +281,8 @@ register_for_removal(const char *pathname) { * quickly created with the same name. */ void -unregister_for_removal(int remove_files) { +unregister_for_removal(int remove_files) +{ if (exit_filelist) { size_t i; @@ -303,7 +305,8 @@ unregister_for_removal(int remove_files) { * any case, unlink it. */ int -m_unlink(const char *pathname) { +m_unlink(const char *pathname) +{ if (exit_filelist) { char **slot = svector_find(exit_filelist, pathname); @@ -321,7 +324,8 @@ m_unlink(const char *pathname) { * Remove all registered temporary files. */ void -remove_registered_files_atexit(void) { +remove_registered_files_atexit(void) +{ unregister_for_removal(1); } @@ -333,7 +337,8 @@ remove_registered_files_atexit(void) { * in case the use was expecting a core dump. */ void -remove_registered_files(int sig) { +remove_registered_files(int sig) +{ struct sigaction act; /*