diff --git a/strbuf.c b/strbuf.c
index dac945c7c8ec3ca14791e472fd19a47cc07dcd15..7f14b0fb59bd7e14979b002f441ae84ff5b0e9a2 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
-#include <stdio.h>
-#include <stdlib.h>
+#include "cache.h"
#include "strbuf.h"
void strbuf_init(struct strbuf *sb) {
- sb->buf = 0;
+ sb->buf = NULL;
sb->eof = sb->alloc = sb->len = 0;
}
static void inline strbuf_add(struct strbuf *sb, int ch) {
if (sb->alloc <= sb->len) {
sb->alloc = sb->alloc * 3 / 2 + 16;
- sb->buf = realloc(sb->buf, sb->alloc);
+ sb->buf = xrealloc(sb->buf, sb->alloc);
}
sb->buf[sb->len++] = ch;
}
break;
strbuf_add(sb, ch);
}
- if (sb->len == 0)
+ if (ch == EOF && sb->len == 0)
sb->eof = 1;
strbuf_end(sb);
}