Use mu_tempfile.
Showing
5 changed files
with
7 additions
and
47 deletions
... | @@ -52,7 +52,7 @@ collect_open_mailbox_file () | ... | @@ -52,7 +52,7 @@ collect_open_mailbox_file () |
52 | int fd; | 52 | int fd; |
53 | 53 | ||
54 | /* Create input mailbox */ | 54 | /* Create input mailbox */ |
55 | fd = util_tempfile (&temp_filename); | 55 | fd = mu_tempfile (NULL, &temp_filename); |
56 | if (fd == -1) | 56 | if (fd == -1) |
57 | exit (1); | 57 | exit (1); |
58 | 58 | ... | ... |
... | @@ -136,7 +136,7 @@ mail_send0 (struct send_environ *env, int save_to) | ... | @@ -136,7 +136,7 @@ mail_send0 (struct send_environ *env, int save_to) |
136 | char *savefile = NULL; | 136 | char *savefile = NULL; |
137 | int int_cnt; | 137 | int int_cnt; |
138 | 138 | ||
139 | fd = util_tempfile (&filename); | 139 | fd = mu_tempfile (NULL, &filename); |
140 | 140 | ||
141 | if (fd == -1) | 141 | if (fd == -1) |
142 | { | 142 | { | ... | ... |
... | @@ -443,7 +443,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) | ... | @@ -443,7 +443,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) |
443 | return 1; | 443 | return 1; |
444 | } | 444 | } |
445 | 445 | ||
446 | fd = util_tempfile(NULL); | 446 | fd = mu_tempfile (NULL, NULL); |
447 | if (fd == -1) | 447 | if (fd == -1) |
448 | return 1; | 448 | return 1; |
449 | 449 | ... | ... |
... | @@ -29,6 +29,7 @@ | ... | @@ -29,6 +29,7 @@ |
29 | #include <fcntl.h> | 29 | #include <fcntl.h> |
30 | 30 | ||
31 | #include <mailutils/stream.h> | 31 | #include <mailutils/stream.h> |
32 | #include <mailutils/mutil.h> | ||
32 | #include <body0.h> | 33 | #include <body0.h> |
33 | 34 | ||
34 | #define BODY_MODIFIED 0x10000 | 35 | #define BODY_MODIFIED 0x10000 |
... | @@ -346,22 +347,5 @@ _body_get_lines0 (stream_t stream, size_t *plines) | ... | @@ -346,22 +347,5 @@ _body_get_lines0 (stream_t stream, size_t *plines) |
346 | static int | 347 | static int |
347 | lazy_create (body_t body) | 348 | lazy_create (body_t body) |
348 | { | 349 | { |
349 | const char *tmpdir = getenv ("TMPDIR"); | 350 | return mu_tempfile (NULL, &body->filename); |
350 | int fd; | ||
351 | if (tmpdir == NULL) | ||
352 | tmpdir = P_tmpdir; | ||
353 | body->filename = calloc (strlen (tmpdir) + 1 + /* "muXXXXXX" */ 8 + 1, | ||
354 | sizeof (char)); | ||
355 | if (body->filename == NULL) | ||
356 | return ENOMEM; | ||
357 | sprintf (body->filename, "%s/muXXXXXX", tmpdir); | ||
358 | #ifdef HAVE_MKSTEMP | ||
359 | fd = mkstemp (body->filename); | ||
360 | #else | ||
361 | if (mktemp (body->filename)) | ||
362 | fd = open (body->filename, O_RDWR|O_CREAT|O_EXCL, 0600); | ||
363 | else | ||
364 | fd = -1; | ||
365 | #endif | ||
366 | return fd; | ||
367 | } | 351 | } | ... | ... |
... | @@ -50,6 +50,7 @@ | ... | @@ -50,6 +50,7 @@ |
50 | #include <mailutils/header.h> | 50 | #include <mailutils/header.h> |
51 | #include <mailutils/attribute.h> | 51 | #include <mailutils/attribute.h> |
52 | #include <mailutils/error.h> | 52 | #include <mailutils/error.h> |
53 | #include <mailutils/mutil.h> | ||
53 | #include <registrar0.h> | 54 | #include <registrar0.h> |
54 | #include <mailbox0.h> | 55 | #include <mailbox0.h> |
55 | 56 | ||
... | @@ -447,34 +448,9 @@ _mh_next_seq (struct _mh_data *mhd) | ... | @@ -447,34 +448,9 @@ _mh_next_seq (struct _mh_data *mhd) |
447 | static FILE * | 448 | static FILE * |
448 | _mh_tempfile(struct _mh_data *mhd, char **namep) | 449 | _mh_tempfile(struct _mh_data *mhd, char **namep) |
449 | { | 450 | { |
450 | char *filename; | 451 | int fd = mu_tempfile (mhd->name, namep); |
451 | int fd; | ||
452 | |||
453 | filename = malloc (strlen (mhd->name) + /*'/'*/1 + /* "muXXXXXX" */8 + 1); | ||
454 | if (!filename) | ||
455 | return NULL; | ||
456 | sprintf (filename, "%s/muXXXXXX", mhd->name); | ||
457 | |||
458 | #ifdef HAVE_MKSTEMP | ||
459 | { | ||
460 | int save_mask = umask (077); | ||
461 | fd = mkstemp (filename); | ||
462 | umask (save_mask); | ||
463 | } | ||
464 | #else | ||
465 | if (mktemp (filename)) | ||
466 | fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600); | ||
467 | else | ||
468 | fd = -1; | ||
469 | #endif | ||
470 | |||
471 | if (fd == -1) | 452 | if (fd == -1) |
472 | { | ||
473 | free (filename); | ||
474 | return NULL; | 453 | return NULL; |
475 | } | ||
476 | |||
477 | *namep = filename; | ||
478 | return fdopen (fd, "w"); | 454 | return fdopen (fd, "w"); |
479 | } | 455 | } |
480 | 456 | ... | ... |
-
Please register or sign in to post a comment