@matheusbsbs / matheus-bagliano / commits / b655d46bb2
Fork 0

Use strbuf_read in builtin-fetch-tool.c.

xrealloc.use --; 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 b655d46bb2d8aa12f3203f93c323b41df161fd26
1 file changed +6 -17
builtin-fetch--tool.c
+6 -17
@@ -2,27 +2,16 @@
2 #include "cache.h"
3 #include "refs.h"
4 #include "commit.h"
5 -
6 -#define CHUNK_SIZE 1024
5 +#include "strbuf.h"
6
7 static char *get_stdin(void)
8 {
10 - size_t offset = 0;
11 - char *data = xmalloc(CHUNK_SIZE);
12 -
13 - while (1) {
14 - ssize_t cnt = xread(0, data + offset, CHUNK_SIZE);
15 - if (cnt < 0)
16 - die("error reading standard input: %s",
17 - strerror(errno));
18 - if (cnt == 0) {
19 - data[offset] = 0;
20 - break;
21 - }
22 - offset += cnt;
23 - data = xrealloc(data, offset + CHUNK_SIZE);
9 + struct strbuf buf;
10 + strbuf_init(&buf, 0);
11 + if (strbuf_read(&buf, 0, 1024) < 0) {
12 + die("error reading standard input: %s", strerror(errno));
13 }
25 - return data;
14 + return strbuf_detach(&buf);
15 }
16
17 static void show_new(enum object_type type, unsigned char *sha1_new)