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>
This commit is contained in:
parent
674d172730
commit
b655d46bb2
@ -2,27 +2,16 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
|
#include "strbuf.h"
|
||||||
#define CHUNK_SIZE 1024
|
|
||||||
|
|
||||||
static char *get_stdin(void)
|
static char *get_stdin(void)
|
||||||
{
|
{
|
||||||
size_t offset = 0;
|
struct strbuf buf;
|
||||||
char *data = xmalloc(CHUNK_SIZE);
|
strbuf_init(&buf, 0);
|
||||||
|
if (strbuf_read(&buf, 0, 1024) < 0) {
|
||||||
while (1) {
|
die("error reading standard input: %s", strerror(errno));
|
||||||
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;
|
return strbuf_detach(&buf);
|
||||||
data = xrealloc(data, offset + CHUNK_SIZE);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_new(enum object_type type, unsigned char *sha1_new)
|
static void show_new(enum object_type type, unsigned char *sha1_new)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user