aboutsummaryrefslogtreecommitdiff
path: root/libio/iofgets.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-09-27 00:00:42 +0000
committerUlrich Drepper <drepper@redhat.com>2005-09-27 00:00:42 +0000
commitb5d839c996d7236ed5788296b4d723e67ec4fdb8 (patch)
treea5220f793e6180e189b99ab8c59401ab01a26f71 /libio/iofgets.c
parent9a5933834ba8f1289024c1ab13e1cd711b5ec3af (diff)
downloadglibc-b5d839c996d7236ed5788296b4d723e67ec4fdb8.zip
glibc-b5d839c996d7236ed5788296b4d723e67ec4fdb8.tar.gz
glibc-b5d839c996d7236ed5788296b4d723e67ec4fdb8.tar.bz2
[BZ #713]
2005-09-26 Ulrich Drepper <drepper@redhat.com> [BZ #713] * libio/iofgets.c: Treat N==1 correctly. * libio/iofgets_u.c: Likewise. * libio/iofgetws.c: Likewise. * libio/iofgetws_u.c: Likewise. * stdio-common/Makefile (tests): Add tst-fgets. * stdio-common/tst-fgets.c: New file.
Diffstat (limited to 'libio/iofgets.c')
-rw-r--r--libio/iofgets.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libio/iofgets.c b/libio/iofgets.c
index 879cc97..601b174 100644
--- a/libio/iofgets.c
+++ b/libio/iofgets.c
@@ -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