Skip to content

Commit

Permalink
Use strbuf_read in builtin-fetch-tool.c.
Browse files Browse the repository at this point in the history
  xrealloc.use --;

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 674d172 commit b655d46
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions builtin-fetch--tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b655d46

Please sign in to comment.