29 |
#include <fcntl.h> |
#include <fcntl.h> |
30 |
|
|
31 |
#include <mailutils/stream.h> |
#include <mailutils/stream.h> |
32 |
|
#include <mailutils/mutil.h> |
33 |
#include <body0.h> |
#include <body0.h> |
34 |
|
|
35 |
#define BODY_MODIFIED 0x10000 |
#define BODY_MODIFIED 0x10000 |
347 |
static int |
static int |
348 |
lazy_create (body_t body) |
lazy_create (body_t body) |
349 |
{ |
{ |
350 |
const char *tmpdir = getenv ("TMPDIR"); |
return mu_tempfile (NULL, &body->filename); |
|
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; |
|
351 |
} |
} |