Code

[PATCH] fix strbuf take #2
authorJunio C Hamano <junkio@cox.net>
Thu, 19 May 2005 06:34:03 +0000 (23:34 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Thu, 19 May 2005 14:31:23 +0000 (07:31 -0700)
I just remembered why I placed that bogus "sb->len ==0 implies
sb->eof" condition there.  We need at least something like this
to catch the normal EOF (that is, line termination immediately
followed by EOF) case.  "if (feof(fp))" fires when we have
already read the eof, not when we are about read it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
strbuf.c

index 654330849c3f5d1502d0116c71595b9fa4613186..672a1e409760d33ad704cec098af3864f06a3a38 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -37,6 +37,8 @@ void read_line(struct strbuf *sb, FILE *fp, int term) {
                        break;
                strbuf_add(sb, ch);
        }
+       if (ch == EOF && sb->len == 0)
+               sb->eof = 1;
        strbuf_end(sb);
 }