Skip to content

Commit

Permalink
Use strbufs to in read_message (imap-send.c), custom buffer--.
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pierre Habouzit authored and Junio C Hamano committed Sep 10, 2007
1 parent b655d46 commit 635d043
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "cache.h"
#include "strbuf.h"

typedef struct store_conf {
char *name;
Expand Down Expand Up @@ -1160,28 +1161,18 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
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;
}

Expand Down

0 comments on commit 635d043

Please sign in to comment.