Commit 34554b52 34554b5234db91e5b79f88c8e2cb0ae82a87e6a2 by Sergey Poznyakoff

Use mu_tempfile.

1 parent f5edbeda
......@@ -52,7 +52,7 @@ collect_open_mailbox_file ()
int fd;
/* Create input mailbox */
fd = util_tempfile (&temp_filename);
fd = mu_tempfile (NULL, &temp_filename);
if (fd == -1)
exit (1);
......
......@@ -136,7 +136,7 @@ mail_send0 (struct send_environ *env, int save_to)
char *savefile = NULL;
int int_cnt;
fd = util_tempfile (&filename);
fd = mu_tempfile (NULL, &filename);
if (fd == -1)
{
......
......@@ -443,7 +443,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
return 1;
}
fd = util_tempfile(NULL);
fd = mu_tempfile (NULL, NULL);
if (fd == -1)
return 1;
......
......@@ -29,6 +29,7 @@
#include <fcntl.h>
#include <mailutils/stream.h>
#include <mailutils/mutil.h>
#include <body0.h>
#define BODY_MODIFIED 0x10000
......@@ -346,22 +347,5 @@ _body_get_lines0 (stream_t stream, size_t *plines)
static int
lazy_create (body_t body)
{
const char *tmpdir = getenv ("TMPDIR");
int fd;
if (tmpdir == NULL)
tmpdir = P_tmpdir;
body->filename = calloc (strlen (tmpdir) + 1 + /* "muXXXXXX" */ 8 + 1,
sizeof (char));
if (body->filename == NULL)
return ENOMEM;
sprintf (body->filename, "%s/muXXXXXX", tmpdir);
#ifdef HAVE_MKSTEMP
fd = mkstemp (body->filename);
#else
if (mktemp (body->filename))
fd = open (body->filename, O_RDWR|O_CREAT|O_EXCL, 0600);
else
fd = -1;
#endif
return fd;
return mu_tempfile (NULL, &body->filename);
}
......
......@@ -50,6 +50,7 @@
#include <mailutils/header.h>
#include <mailutils/attribute.h>
#include <mailutils/error.h>
#include <mailutils/mutil.h>
#include <registrar0.h>
#include <mailbox0.h>
......@@ -447,34 +448,9 @@ _mh_next_seq (struct _mh_data *mhd)
static FILE *
_mh_tempfile(struct _mh_data *mhd, char **namep)
{
char *filename;
int fd;
filename = malloc (strlen (mhd->name) + /*'/'*/1 + /* "muXXXXXX" */8 + 1);
if (!filename)
return NULL;
sprintf (filename, "%s/muXXXXXX", mhd->name);
#ifdef HAVE_MKSTEMP
{
int save_mask = umask (077);
fd = mkstemp (filename);
umask (save_mask);
}
#else
if (mktemp (filename))
fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600);
else
fd = -1;
#endif
int fd = mu_tempfile (mhd->name, namep);
if (fd == -1)
{
free (filename);
return NULL;
}
*namep = filename;
return fdopen (fd, "w");
}
......