提交 b655d46b 编写于 作者: P Pierre Habouzit 提交者: Junio C Hamano

Use strbuf_read in builtin-fetch-tool.c.

  xrealloc.use --;
Signed-off-by: NPierre Habouzit <madcoder@debian.org>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 674d1727
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册