Return an error only if there is a new error.

This commit is contained in:
Ulrich Drepper 1998-01-30 16:57:37 +00:00
parent 651914fe07
commit f0313cd308
2 changed files with 14 additions and 0 deletions

View File

@ -33,11 +33,17 @@ _IO_fgets (buf, n, fp)
{
_IO_size_t count;
char *result;
int old_error;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (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 = _IO_getline (fp, buf, n - 1, '\n', 1);
if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
result = NULL;
@ -46,6 +52,7 @@ _IO_fgets (buf, n, fp)
buf[count] = '\0';
result = buf;
}
fp->_IO_file_flags |= old_error;
_IO_cleanup_region_end (1);
return result;
}

View File

@ -46,6 +46,11 @@ _IO_gets (buf)
count = 0;
else
{
/* 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. */
int old_error = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN;
_IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN;
buf[0] = (char)ch;
count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
@ -53,6 +58,8 @@ _IO_gets (buf)
retval = NULL;
goto unlock_return;
}
else
_IO_stdin->_IO_file_flags |= old_error;
}
buf[count] = 0;
retval = buf;