]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Return an error only if there is a new error.
authorUlrich Drepper <drepper@redhat.com>
Fri, 30 Jan 1998 16:57:37 +0000 (16:57 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 30 Jan 1998 16:57:37 +0000 (16:57 +0000)
libio/iofgets.c
libio/iogets.c

index 7a1044f8018820a5686eacd24be7a45d7e066f72..24f8333708ddd2b6ff4d1deddfe08dec45bc8820 100644 (file)
@@ -33,11 +33,17 @@ _IO_fgets (buf, n, fp)
 {
   _IO_size_t count;
   char *result;
+  int old_error;
   CHECK_FILE (fp, NULL);
   if (n <= 0)
     return NULL;
   _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
   _IO_flockfile (fp);
+  /* This is very tricky since a file descriptor may be in the
+     non-blocking mode. The error flag doesn't mean much in this
+     case. We return an error only when there is a new error. */
+  old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
+  fp->_IO_file_flags &= ~_IO_ERR_SEEN;
   count = _IO_getline (fp, buf, n - 1, '\n', 1);
   if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
     result = NULL;
@@ -46,6 +52,7 @@ _IO_fgets (buf, n, fp)
       buf[count] = '\0';
       result = buf;
     }
+  fp->_IO_file_flags |= old_error;
   _IO_cleanup_region_end (1);
   return result;
 }
index 0e87504107cad20c7724c99b9135f6efb4cc9428..5bf3f234cbebb2d9bb21e0ee50c060e1c1491f5c 100644 (file)
@@ -46,6 +46,11 @@ _IO_gets (buf)
     count = 0;
   else
     {
+      /* This is very tricky since a file descriptor may be in the
+        non-blocking mode. The error flag doesn't mean much in this
+        case. We return an error only when there is a new error. */
+      int old_error = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN;
+      _IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN;
       buf[0] = (char)ch;
       count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
       if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
@@ -53,6 +58,8 @@ _IO_gets (buf)
          retval = NULL;
          goto unlock_return;
        }
+      else
+       _IO_stdin->_IO_file_flags |= old_error;
     }
   buf[count] = 0;
   retval = buf;