summaryrefslogtreecommitdiff
path: root/libmailutils/base/amd.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-11-25 17:12:32 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-11-25 19:39:53 +0200
commit8acde412feee7235b342196182c69d0ed25fe1fc (patch)
treed03411665f570504b028be70d1c48c01a61e6237 /libmailutils/base/amd.c
parent80bb8b2fc30ba04dda9eb652519c65897542437e (diff)
downloadmailutils-8acde412feee7235b342196182c69d0ed25fe1fc.tar.gz
mailutils-8acde412feee7235b342196182c69d0ed25fe1fc.tar.bz2
Rewrite temporary file handling.
* include/mailutils/util.h (mu_make_file_name_suf): New proto. (mu_make_file_name): Replace with a macro. (MU_TEMPFILE_TMPDIR,MU_TEMPFILE_SUFFIX) (MU_TEMPFILE_MKDIR): New flags. (mu_tempfile_hints): New struct. (mu_tempfile): Change signature. * libmailutils/base/tempfile.c (mu_create_temp_file): New function. (mu_tempfile): Rewrite from scratch. Change signature. All callers changed. * libmailutils/string/mkfilename.c (mu_make_file_name): Remove. (mu_make_file_name_suf): New function. * libmailutils/stream/streamcpy.c (mu_stream_copy): Don't return EIO on EOF. * libmailutils/stream/file_stream.c (mu_fd_stream_create): If MU_STREAM_SEEK is set, position fd to 0. * guimb/collect.c: Update calls to mu_tempfile. * lib/mailcap.c: Likewise. * libmailutils/base/amd.c (_amd_tempfile): Rewrite using mu_tempfile. * libmailutils/tests/tempfile.c: New file. * libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add tempfile.
Diffstat (limited to 'libmailutils/base/amd.c')
-rw-r--r--libmailutils/base/amd.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index d51f94127..db665b461 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -597,13 +597,18 @@ amd_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
return ENOSYS;
}
-static FILE *
-_amd_tempfile(struct _amd_data *amd, char **namep)
+static int
+_amd_tempfile (struct _amd_data *amd, FILE **pfile, char **namep)
{
- int fd = mu_tempfile (amd->name, namep);
- if (fd == -1)
- return NULL;
- return fdopen (fd, "w");
+ struct mu_tempfile_hints hints;
+ int fd, rc;
+
+ hints.tmpdir = amd->name;
+ rc = mu_tempfile (&hints, MU_TEMPFILE_TMPDIR, &fd, namep);
+ if (rc == 0)
+ if ((*pfile = fdopen (fd, "w")) == NULL)
+ rc = errno;
+ return rc;
}
static int
@@ -658,11 +663,11 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
return status;
}
- fp = _amd_tempfile (mhm->amd, &name);
- if (!fp)
+ status = _amd_tempfile (mhm->amd, &fp, &name);
+ if (status)
{
free (msg_name);
- return errno;
+ return status;
}
/* Try to allocate large buffer */

Return to:

Send suggestions and report system problems to the System administrator.