diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-05-01 01:39:49 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-09-08 16:06:03 +0300 |
commit | d17ec29ca42139df7588ee4f85bbeb8bd20c93e8 (patch) | |
tree | ac4ced333e51eb6c98c2ff1ee86aa2e35232118a /mh/comp.c | |
parent | 3437509ff40a5e7cc86f8b26fb182592cab43b74 (diff) | |
download | mailutils-d17ec29ca42139df7588ee4f85bbeb8bd20c93e8.tar.gz mailutils-d17ec29ca42139df7588ee4f85bbeb8bd20c93e8.tar.bz2 |
Use stringrefs, add some guidelines for further editing.
* comsat/action.c
* imap4d/fetch.c
* imap4d/search.c
* mh/burst.c
* mh/comp.c
* mh/forw.c
* mh/mh_ctx.c
* mh/mh_format.c
* mh/mh_list.c
* mh/mhn.c
* mh/pick.y
* pop3d/retr.c
* pop3d/top.c
* readmsg/msglist.c
* readmsg/readmsg.c
Diffstat (limited to 'mh/comp.c')
-rw-r--r-- | mh/comp.c | 41 |
1 files changed, 11 insertions, 30 deletions
@@ -160,49 +160,30 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) mu_stream_t in; mu_stream_t out; int rc; - size_t size; - char *buffer; - size_t bufsize, rdsize; mu_mailbox_get_message (mbox, n, &msg); - mu_message_size (msg, &size); - - for (bufsize = size; bufsize > 0 && (buffer = malloc (bufsize)) == 0; - bufsize /= 2) - ; - - if (!bufsize) - mh_err_memory (1); - - mu_message_get_stream (msg, &in); + mu_message_get_streamref (msg, &in); if ((rc = mu_file_stream_create (&out, - file, MU_STREAM_RDWR|MU_STREAM_CREAT)) != 0 + file, MU_STREAM_RDWR|MU_STREAM_CREAT)) != 0 || (rc = mu_stream_open (out))) { mu_error (_("cannot open output file \"%s\": %s"), file, mu_strerror (rc)); - free (buffer); - return 1; - } - - mu_stream_seek (in, 0, MU_SEEK_SET, NULL); - while (size > 0 - && (rc = mu_stream_read (in, buffer, bufsize, &rdsize)) == 0 - && rdsize > 0) - { - if ((rc = mu_stream_write (out, buffer, rdsize, NULL)) != 0) - { - mu_error (_("error writing to \"%s\": %s"), - file, mu_strerror (rc)); - break; - } - size -= rdsize; + mu_stream_destroy (&in); + return rc; } + rc = mu_stream_copy (out, in, 0); + mu_stream_destroy (&in); mu_stream_close (out); mu_stream_destroy (&out); + if (rc) + { + mu_error (_("error copying to \"%s\": %s"), + file, mu_strerror (rc)); + } return rc; } |