]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - debug/fgets_chk.c
Fix REALLOC_ZERO_BYTES_FREES comment to match C17
[thirdparty/glibc.git] / debug / fgets_chk.c
index 046ac1d12f18dd60f8976e3a4b5d9074f4da6175..de6ff7797f34f71c8bfa1c86717e3933435d329f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993-2012 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -13,7 +13,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.
+   <https://www.gnu.org/licenses/>.
 
    As a special exception, if you link the code in this file with
    files compiled with a GNU compiler to produce an executable,
 #include <sys/param.h>
 
 char *
-__fgets_chk (buf, size, n, fp)
-     char *buf;
-     size_t size;
-     int n;
-     _IO_FILE *fp;
+__fgets_chk (char *buf, size_t size, int n, FILE *fp)
 {
-  _IO_size_t count;
+  size_t count;
   char *result;
   CHECK_FILE (fp, NULL);
   if (n <= 0)
@@ -44,13 +40,12 @@ __fgets_chk (buf, size, n, 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. */
-  int old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
-  fp->_IO_file_flags &= ~_IO_ERR_SEEN;
+  int old_error = fp->_flags & _IO_ERR_SEEN;
+  fp->_flags &= ~_IO_ERR_SEEN;
   count = _IO_getline (fp, buf, MIN ((size_t) n - 1, size), '\n', 1);
   /* If we read in some bytes and errno is EAGAIN, that error will
      be reported for next read. */
-  if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
-                    && errno != EAGAIN))
+  if (count == 0 || ((fp->_flags & _IO_ERR_SEEN) && errno != EAGAIN))
     result = NULL;
   else if (count >= size)
     __chk_fail ();
@@ -59,7 +54,7 @@ __fgets_chk (buf, size, n, fp)
       buf[count] = '\0';
       result = buf;
     }
-  fp->_IO_file_flags |= old_error;
+  fp->_flags |= old_error;
   _IO_release_lock (fp);
   return result;
 }