summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-17 09:19:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-09-18 07:55:10 (GMT)
commite6c019d0b0140fae1cdfd661746cbe319b6c3670 (patch)
tree5711e59da3bda8207a41173df8d6a6b66696b7b5 /strbuf.c
parent8b6087fb25068d6af927f112a93dc056930f3108 (diff)
downloadgit-e6c019d0b0140fae1cdfd661746cbe319b6c3670.zip
git-e6c019d0b0140fae1cdfd661746cbe319b6c3670.tar.gz
git-e6c019d0b0140fae1cdfd661746cbe319b6c3670.tar.bz2
Drop strbuf's 'eof' marker, and make read_line a first class citizen.
read_line is now strbuf_getline, and is a first class citizen, it returns 0 when reading a line worked, EOF else. The ->eof marker was used non-locally by fast-import.c, mimic the same behaviour using a static int in "read_next_command", that now returns -1 on EOF, and avoids to call strbuf_getline when it's in EOF state. Also no longer automagically strbuf_release the buffer, it's counter intuitive and breaks fast-import in a very subtle way. Note: being at EOF implies that command_buf.len == 0. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/strbuf.c b/strbuf.c
index c5f9e2a..59383ac 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -17,7 +17,6 @@ void strbuf_reset(struct strbuf *sb)
{
if (sb->len)
strbuf_setlen(sb, 0);
- sb->eof = 0;
}
char *strbuf_detach(struct strbuf *sb)
@@ -145,14 +144,13 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
return sb->len - oldlen;
}
-void read_line(struct strbuf *sb, FILE *fp, int term)
+int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
{
int ch;
- if (feof(fp)) {
- strbuf_release(sb);
- sb->eof = 1;
- return;
- }
+
+ strbuf_grow(sb, 0);
+ if (feof(fp))
+ return EOF;
strbuf_reset(sb);
while ((ch = fgetc(fp)) != EOF) {
@@ -161,11 +159,9 @@ void read_line(struct strbuf *sb, FILE *fp, int term)
strbuf_grow(sb, 1);
sb->buf[sb->len++] = ch;
}
- if (ch == EOF && sb->len == 0) {
- strbuf_release(sb);
- sb->eof = 1;
- }
+ if (ch == EOF && sb->len == 0)
+ return EOF;
- strbuf_grow(sb, 1);
sb->buf[sb->len] = '\0';
+ return 0;
}