summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b655d46)
raw | patch | inline | side by side (parent: b655d46)
author | Pierre Habouzit <madcoder@debian.org> | |
Mon, 10 Sep 2007 10:35:08 +0000 (12:35 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 10 Sep 2007 19:50:42 +0000 (12:50 -0700) |
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
imap-send.c | patch | blob | history |
diff --git a/imap-send.c b/imap-send.c
index a5a069608419a8ecc42be63eb7998efd262f0ddc..ecd4216a560095a00a7da5bbe41655aa97f56731 100644 (file)
--- a/imap-send.c
+++ b/imap-send.c
*/
#include "cache.h"
+#include "strbuf.h"
typedef struct store_conf {
char *name;
static int
read_message( FILE *f, msg_data_t *msg )
{
- int len, r;
+ struct strbuf buf;
- memset( msg, 0, sizeof *msg );
- len = CHUNKSIZE;
- msg->data = xmalloc( len+1 );
- msg->data[0] = 0;
-
- while(!feof( f )) {
- if (msg->len >= len) {
- void *p;
- len += CHUNKSIZE;
- p = xrealloc(msg->data, len+1);
- if (!p)
- break;
- msg->data = p;
- }
- r = fread( &msg->data[msg->len], 1, len - msg->len, f );
- if (r <= 0)
+ memset(msg, 0, sizeof(*msg));
+ strbuf_init(&buf, 0);
+
+ do {
+ if (strbuf_fread(&buf, CHUNKSIZE, f) <= 0)
break;
- msg->len += r;
- }
- msg->data[msg->len] = 0;
+ } while (!feof(f));
+
+ msg->len = buf.len;
+ msg->data = strbuf_detach(&buf);
return msg->len;
}