aboutsummaryrefslogtreecommitdiff
path: root/libio/iogetline.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/iogetline.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/iogetline.c')
-rw-r--r--libio/iogetline.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/libio/iogetline.c b/libio/iogetline.c
index eca38cf..022a444 100644
--- a/libio/iogetline.c
+++ b/libio/iogetline.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993,1997,1998,2000,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993,1997,1998,2000,2001,2002,2005
+ 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
@@ -73,7 +74,8 @@ _IO_getline_info (fp, buf, n, delim, extract_delim, eof)
int c = __uflow (fp);
if (c == EOF)
{
- if (eof) *eof = c;
+ if (eof)
+ *eof = c;
break;
}
if (c == delim)
@@ -89,31 +91,31 @@ _IO_getline_info (fp, buf, n, delim, extract_delim, eof)
*ptr++ = c;
n--;
}
- else
- {
- char *t;
- if ((_IO_size_t) len >= n)
- len = n;
- t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
- if (t != NULL)
- {
- _IO_size_t old_len = ptr-buf;
- len = t - fp->_IO_read_ptr;
- if (extract_delim >= 0)
- {
- ++t;
- if (extract_delim > 0)
- ++len;
- }
- memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
- fp->_IO_read_ptr = t;
- return old_len + len;
- }
- memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
- fp->_IO_read_ptr += len;
- ptr += len;
- n -= len;
- }
+ else
+ {
+ char *t;
+ if ((_IO_size_t) len >= n)
+ len = n;
+ t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
+ if (t != NULL)
+ {
+ _IO_size_t old_len = ptr-buf;
+ len = t - fp->_IO_read_ptr;
+ if (extract_delim >= 0)
+ {
+ ++t;
+ if (extract_delim > 0)
+ ++len;
+ }
+ memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
+ fp->_IO_read_ptr = t;
+ return old_len + len;
+ }
+ memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
+ fp->_IO_read_ptr += len;
+ ptr += len;
+ n -= len;
+ }
}
return ptr - buf;
}