]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-fetch--tool.c
Drop strbuf's 'eof' marker, and make read_line a first class citizen.
[git.git] / builtin-fetch--tool.c
index 24c7e6f7dbcee4d02daad7182bb7587c4c9c3418..514a3cc018651d1257d9f88d78f2c208148c7f19 100644 (file)
@@ -3,26 +3,14 @@
 #include "refs.h"
 #include "commit.h"
 
-#define CHUNK_SIZE 1024
-
 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)