]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - libio/iofgets.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / libio / iofgets.c
index 601b1746a10d482e51058d8f2a437365ce4f8b66..d57e42c0911acf0717c4a952e8c66cad34e633ec 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2005
-   Free Software Foundation, Inc.
+/* Copyright (C) 1993-2019 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,9 +12,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.
+   License along with the GNU C Library; if not, see
+   <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 <stdio.h>
 
 char *
-_IO_fgets (buf, n, fp)
-     char *buf;
-     int n;
-     _IO_FILE *fp;
+_IO_fgets (char *buf, int n, FILE *fp)
 {
-  _IO_size_t count;
+  size_t count;
   char *result;
   int old_error;
   CHECK_FILE (fp, NULL);
   if (n <= 0)
     return NULL;
-  if (__builtin_expect (n == 1, 0))
+  if (__glibc_unlikely (n == 1))
     {
       /* Another irregular case: since we have to store a NUL byte and
         there is only room for exactly one byte, we don't have to
@@ -53,29 +48,28 @@ _IO_fgets (buf, 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. */
-  old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
-  fp->_IO_file_flags &= ~_IO_ERR_SEEN;
-  count = INTUSE(_IO_getline) (fp, buf, n - 1, '\n', 1);
+  old_error = fp->_flags & _IO_ERR_SEEN;
+  fp->_flags &= ~_IO_ERR_SEEN;
+  count = _IO_getline (fp, buf, n - 1, '\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
     {
       buf[count] = '\0';
       result = buf;
     }
-  fp->_IO_file_flags |= old_error;
+  fp->_flags |= old_error;
   _IO_release_lock (fp);
   return result;
 }
 
-#ifdef weak_alias
 weak_alias (_IO_fgets, fgets)
 
 # ifndef _IO_MTSAFE_IO
+strong_alias (_IO_fgets, __fgets_unlocked)
+libc_hidden_def (__fgets_unlocked)
 weak_alias (_IO_fgets, fgets_unlocked)
 libc_hidden_weak (fgets_unlocked)
 # endif
-#endif