]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - libio/iofgets.c
2.5-18.1
[thirdparty/glibc.git] / libio / iofgets.c
index 879cc975a3c72909b3a60f3e90b1b5e7a8da479c..601b1746a10d482e51058d8f2a437365ce4f8b66 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003
+/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2005
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -41,6 +41,14 @@ _IO_fgets (buf, n, fp)
   CHECK_FILE (fp, NULL);
   if (n <= 0)
     return NULL;
+  if (__builtin_expect (n == 1, 0))
+    {
+      /* 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
+        read anything.  */
+      buf[0] = '\0';
+      return buf;
+    }
   _IO_acquire_lock (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