mirror of
https://github.com/git/git.git
synced 2024-11-15 17:13:16 +01:00
85023577a8
This is a mechanical clean-up of the way *.c files include system header files. (1) sources under compat/, platform sha-1 implementations, and xdelta code are exempt from the following rules; (2) the first #include must be "git-compat-util.h" or one of our own header file that includes it first (e.g. config.h, builtin.h, pkt-line.h); (3) system headers that are included in "git-compat-util.h" need not be included in individual C source files. (4) "git-compat-util.h" does not have to include subsystem specific header files (e.g. expat.h). Signed-off-by: Junio C Hamano <junkio@cox.net>
43 lines
768 B
C
43 lines
768 B
C
#include "cache.h"
|
|
#include "strbuf.h"
|
|
|
|
void strbuf_init(struct strbuf *sb) {
|
|
sb->buf = NULL;
|
|
sb->eof = sb->alloc = sb->len = 0;
|
|
}
|
|
|
|
static void strbuf_begin(struct strbuf *sb) {
|
|
free(sb->buf);
|
|
strbuf_init(sb);
|
|
}
|
|
|
|
static void inline strbuf_add(struct strbuf *sb, int ch) {
|
|
if (sb->alloc <= sb->len) {
|
|
sb->alloc = sb->alloc * 3 / 2 + 16;
|
|
sb->buf = xrealloc(sb->buf, sb->alloc);
|
|
}
|
|
sb->buf[sb->len++] = ch;
|
|
}
|
|
|
|
static void strbuf_end(struct strbuf *sb) {
|
|
strbuf_add(sb, 0);
|
|
}
|
|
|
|
void read_line(struct strbuf *sb, FILE *fp, int term) {
|
|
int ch;
|
|
strbuf_begin(sb);
|
|
if (feof(fp)) {
|
|
sb->eof = 1;
|
|
return;
|
|
}
|
|
while ((ch = fgetc(fp)) != EOF) {
|
|
if (ch == term)
|
|
break;
|
|
strbuf_add(sb, ch);
|
|
}
|
|
if (ch == EOF && sb->len == 0)
|
|
sb->eof = 1;
|
|
strbuf_end(sb);
|
|
}
|
|
|