From: Pierre Habouzit Date: Mon, 10 Sep 2007 10:35:07 +0000 (+0200) Subject: Use strbuf_read in builtin-fetch-tool.c. X-Git-Tag: v1.5.4-rc0~295^2~22 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b655d46bb2d8aa12f3203f93c323b41df161fd26;p=git.git Use strbuf_read in builtin-fetch-tool.c. xrealloc.use --; Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c index 24c7e6f7d..90bdc32d1 100644 --- a/builtin-fetch--tool.c +++ b/builtin-fetch--tool.c @@ -2,27 +2,16 @@ #include "cache.h" #include "refs.h" #include "commit.h" - -#define CHUNK_SIZE 1024 +#include "strbuf.h" static char *get_stdin(void) { - size_t offset = 0; - char *data = xmalloc(CHUNK_SIZE); - - while (1) { - ssize_t cnt = xread(0, data + offset, CHUNK_SIZE); - if (cnt < 0) - die("error reading standard input: %s", - strerror(errno)); - if (cnt == 0) { - data[offset] = 0; - break; - } - offset += cnt; - data = xrealloc(data, offset + CHUNK_SIZE); + struct strbuf buf; + strbuf_init(&buf, 0); + if (strbuf_read(&buf, 0, 1024) < 0) { + die("error reading standard input: %s", strerror(errno)); } - return data; + return strbuf_detach(&buf); } static void show_new(enum object_type type, unsigned char *sha1_new)