All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: git@vger.kernel.org
Cc: Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH 5/6] Use strbufs to in read_message (imap-send.c), custom buffer--.
Date: Sun,  9 Sep 2007 02:04:35 +0200	[thread overview]
Message-ID: <11892962771756-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <11892962771947-git-send-email-madcoder@debian.org>

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 imap-send.c |   31 +++++++++++--------------------
 1 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/imap-send.c b/imap-send.c
index a5a0696..d3dc5dd 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -23,6 +23,7 @@
  */
 
 #include "cache.h"
+#include "strbuf.h"
 
 typedef struct store_conf {
 	char *name;
@@ -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);
+
+	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;
 }
 
-- 
1.5.3.1

  reply	other threads:[~2007-09-09  8:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  0:04 Use more strbufs series [on top of next] Pierre Habouzit
2007-09-09  0:04 ` [PATCH 1/6] Add strbuf_rtrim and strbuf_insert Pierre Habouzit
2007-09-09  0:04   ` [PATCH 2/6] Change semantics of interpolate to work like snprintf Pierre Habouzit
2007-09-09  0:04     ` [PATCH 3/6] Rework pretty_print_commit to use strbufs instead of custom buffers Pierre Habouzit
2007-09-09  0:04       ` [PATCH 4/6] Use strbuf_read in builtin-fetch-tool.c Pierre Habouzit
2007-09-09  0:04         ` Pierre Habouzit [this message]
2007-09-09  0:04           ` [PATCH 6/6] Replace all read_fd use with strbuf_read, and get rid of it Pierre Habouzit
     [not found]       ` <7vsl5nflj2.fsf@gitster.siamese.dyndns.org>
     [not found]         ` <20070910090656.GC3417@artemis.corp>
     [not found]           ` <7vir6isvu1.fsf@gitster.siamese.dyndns.org>
     [not found]             ` <7v642iqumt.fsf@gitster.siamese.dyndns.org>
     [not found]               ` <20070910183256.GD32442@artemis.corp>
2007-09-27 22:56                 ` return void expressions in C (Was: [PATCH 3/6] Rework pretty_print_commit ...) Linus Torvalds
2007-09-09  0:12 ` Use more strbufs series [on top of next] Pierre Habouzit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11892962771756-git-send-email-madcoder@debian.org \
    --to=madcoder@debian.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.