{
_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;
buf[count] = '\0';
result = buf;
}
+ fp->_IO_file_flags |= old_error;
_IO_cleanup_region_end (1);
return result;
}
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)
retval = NULL;
goto unlock_return;
}
+ else
+ _IO_stdin->_IO_file_flags |= old_error;
}
buf[count] = 0;
retval = buf;