1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-16 14:04:52 +01:00
git/strbuf.c
Junio C Hamano a6080a0a44 War on whitespace
This uses "git-apply --whitespace=strip" to fix whitespace errors that have
crept in to our source files over time.  There are a few files that need
to have trailing whitespaces (most notably, test vectors).  The results
still passes the test, and build result in Documentation/ area is unchanged.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-06-07 00:04:01 -07:00

41 lines
767 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);
}