Use strbufs to in read_message (imap-send.c), custom buffer--.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pierre Habouzit 2007-09-10 12:35:08 +02:00 committed by Junio C Hamano
parent b655d46bb2
commit 635d043f30

View File

@ -23,6 +23,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "strbuf.h"
typedef struct store_conf { typedef struct store_conf {
char *name; char *name;
@ -1160,28 +1161,18 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
static int static int
read_message( FILE *f, msg_data_t *msg ) read_message( FILE *f, msg_data_t *msg )
{ {
int len, r; struct strbuf buf;
memset( msg, 0, sizeof *msg ); memset(msg, 0, sizeof(*msg));
len = CHUNKSIZE; strbuf_init(&buf, 0);
msg->data = xmalloc( len+1 );
msg->data[0] = 0;
while(!feof( f )) { do {
if (msg->len >= len) { if (strbuf_fread(&buf, CHUNKSIZE, f) <= 0)
void *p;
len += CHUNKSIZE;
p = xrealloc(msg->data, len+1);
if (!p)
break; break;
msg->data = p; } while (!feof(f));
}
r = fread( &msg->data[msg->len], 1, len - msg->len, f ); msg->len = buf.len;
if (r <= 0) msg->data = strbuf_detach(&buf);
break;
msg->len += r;
}
msg->data[msg->len] = 0;
return msg->len; return msg->len;
} }