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>
Pierre Habouzit committed
Sep 10, 2007 at 12:35 UTC
635d043f30c60f5ec8121bd94304e529f90407c7
1 file changed
+11
-20
imap-send.c
+11
-20
@@ -23,6 +23,7 @@
23
*/
24
25
#include "cache.h"
26
+#include "strbuf.h"
27
28
typedef struct store_conf {
29
char *name;
@@ -1160,28 +1161,18 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int *uid )
1161
static int
1162
read_message( FILE *f, msg_data_t *msg )
1163
{
1163
- int len, r;
1164
+ struct strbuf buf;
1165
1165
- memset( msg, 0, sizeof *msg );
1166
- len = CHUNKSIZE;
1167
- msg->data = xmalloc( len+1 );
1168
- msg->data[0] = 0;
1169
-
1170
- while(!feof( f )) {
1171
- if (msg->len >= len) {
1172
- void *p;
1173
- len += CHUNKSIZE;
1174
- p = xrealloc(msg->data, len+1);
1175
- if (!p)
1176
- break;
1177
- msg->data = p;
1178
- }
1179
- r = fread( &msg->data[msg->len], 1, len - msg->len, f );
1180
- if (r <= 0)
1166
+ memset(msg, 0, sizeof(*msg));
1167
+ strbuf_init(&buf, 0);
1168
+
1169
+ do {
1170
+ if (strbuf_fread(&buf, CHUNKSIZE, f) <= 0)
1171
break;
1182
- msg->len += r;
1183
- }
1184
- msg->data[msg->len] = 0;
1172
+ } while (!feof(f));
1173
+
1174
+ msg->len = buf.len;
1175
+ msg->data = strbuf_detach(&buf);
1176
return msg->len;
1177
}
1178