]> granicus.if.org Git - mutt/commitdiff
Fix mutt_read_line's behaviour when encountering an EOF. From Aaron
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 12 Feb 2001 10:30:41 +0000 (10:30 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 12 Feb 2001 10:30:41 +0000 (10:30 +0000)
Lehmann <aaronl@vitelus.com>.

lib.c

diff --git a/lib.c b/lib.c
index 9db9ffd8bf927e8c42e2cb825986279a0ee6289d..84974a26ea9e948dd0451c0cb2635fa97e17261d 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -464,18 +464,28 @@ char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line)
        return s;
       offset = ch - s - 1;
     }
-    else if (feof (fp))
-    {
-      /* The last line of fp isn't \n terminated */
-      (*line)++;
-      return s;
-    }
     else
     {
-      /* There wasn't room for the line -- increase ``s'' */
-      offset = *size - 1; /* overwrite the terminating 0 */
-      *size += STRING;
-      safe_realloc ((void **) &s, *size);
+      int c;
+      c = getc (fp); /* This is kind of a hack. We want to know if the
+                        char at the current point in the input stream is EOF.
+                        feof() will only tell us if we've already hit EOF, not
+                        if the next character is EOF. So, we need to read in
+                        the next character and manually check if it is EOF. */
+      if (c == EOF)
+      {
+        /* The last line of fp isn't \n terminated */
+        (*line)++;
+        return s;
+      }
+      else
+      {
+        ungetc (c, fp); /* undo our dammage */
+        /* There wasn't room for the line -- increase ``s'' */
+        offset = *size - 1; /* overwrite the terminating 0 */
+        *size += STRING;
+        safe_realloc ((void **) &s, *size);
+      }
     }
   }
 }