bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] invalid use of errno after ferror


From: Paul Eggert
Subject: Re: [Bug-gnulib] invalid use of errno after ferror
Date: 16 Sep 2003 13:06:07 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Jim Meyering <address@hidden> writes:

> When ferror returns nonzero, doesn't that suggest that
> the preceding printf failed, e.g., with a write error?

Yes, sorry, I missed the fact that the preceding printf was the
only output operation that had been applied to the output since
the output was opened or was tested via ferror.

> I'd really like to continue to use errno values, especially those
> that result from failing to close or to flush an output stream.

OK, I will prepare another patch and send it off to bug-coreutils only.
My patch will depend on the following gnulib patch, which I've installed.

2003-09-16  Paul Eggert  <address@hidden>

        * linebuffer.c (readlinebuffer): Return NULL immediately upon
        input error, instead of returning NULL the next time we are called
        (and therefore losing track of errno).

--- linebuffer.c.~1.14.~        Tue Sep  9 14:51:00 2003
+++ linebuffer.c        Tue Sep 16 13:00:30 2003
@@ -45,7 +45,9 @@ initbuffer (struct linebuffer *linebuffe
    that ends in a non-newline character.  Do not null terminate.
    Therefore the stream can contain NUL bytes, and the length
    (including the newline) is returned in linebuffer->length.
-   Return NULL upon error, or when STREAM is empty.
+   Return NULL when stream is empty.  Return NULL and set errno upon
+   error; callers can distinguish this case from the empty case by
+   invoking ferror (stream).
    Otherwise, return LINEBUFFER.  */
 struct linebuffer *
 readlinebuffer (struct linebuffer *linebuffer, FILE *stream)
@@ -55,7 +57,7 @@ readlinebuffer (struct linebuffer *lineb
   char *p = linebuffer->buffer;
   char *end = buffer + linebuffer->size; /* Sentinel. */
 
-  if (feof (stream) || ferror (stream))
+  if (feof (stream))
     return NULL;
 
   do
@@ -63,7 +65,7 @@ readlinebuffer (struct linebuffer *lineb
       c = getc (stream);
       if (c == EOF)
        {
-         if (p == buffer)
+         if (p == buffer || ferror (stream))
            return NULL;
          if (p[-1] == '\n')
            break;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]