summaryrefslogtreecommitdiff
path: root/libio/iofgets.c
diff options
context:
space:
mode:
Diffstat (limited to 'libio/iofgets.c')
-rw-r--r--libio/iofgets.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/libio/iofgets.c b/libio/iofgets.c
index a9f161dce8..88d4bd518e 100644
--- a/libio/iofgets.c
+++ b/libio/iofgets.c
@@ -31,14 +31,21 @@ _IO_fgets (buf, n, fp)
_IO_FILE* fp;
{
_IO_size_t count;
+ char *result;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
+ _IO_flockfile (fp);
count = _IO_getline (fp, buf, n - 1, '\n', 1);
if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
- return NULL;
- buf[count] = 0;
- return buf;
+ result = NULL;
+ else
+ {
+ buf[count] = '\0';
+ result = buf;
+ }
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_fgets, fgets)