From 1ee8eee7896f4b2790a1791c57cb320c54d659e2 Mon Sep 17 00:00:00 2001 From: hpa Date: Sun, 21 Aug 2005 22:36:30 +0000 Subject: [PATCH] Actually decrement counter; return string if EOF after reading characters (i.e. partial line at end of file) --- com32/lib/fgets.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com32/lib/fgets.c b/com32/lib/fgets.c index 88a145a..593bea3 100644 --- a/com32/lib/fgets.c +++ b/com32/lib/fgets.c @@ -17,11 +17,12 @@ char *fgets(char *s, int n, FILE *f) ch = getc(f); if ( ch == EOF ) { *p = '\0'; - return NULL; + return (p == s) ? NULL : s; } *p++ = ch; if ( ch == '\n' ) break; + n--; } if ( n ) *p = '\0'; -- 2.7.4