libc+libos: Properly propagate errors through fgetc() and File::getchar()
This restores proper ^C behavior in the shell.
This commit is contained in:
parent
d0ceec6952
commit
aac8280e8a
@ -432,7 +432,12 @@ extern "C"
|
||||
{
|
||||
u8 value;
|
||||
ssize_t rc = read_from_buffer(stream, &value, 1);
|
||||
if (rc <= 0) return EOF;
|
||||
if (rc < 0)
|
||||
{
|
||||
stream->_err = 1;
|
||||
return EOF;
|
||||
}
|
||||
else if (rc == 0) { return EOF; }
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -149,9 +149,9 @@ namespace os
|
||||
int current;
|
||||
while (true)
|
||||
{
|
||||
current = fgetc(m_file);
|
||||
current = TRY(getchar());
|
||||
|
||||
if (current == -1) break;
|
||||
if (current == EOF) break;
|
||||
|
||||
TRY(data.try_append((char)current));
|
||||
|
||||
@ -208,7 +208,9 @@ namespace os
|
||||
|
||||
Result<int> File::getchar()
|
||||
{
|
||||
return fgetc(m_file);
|
||||
int rc = fgetc(m_file);
|
||||
if (rc == EOF && ferror(m_file)) return err(errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void File::set_close_on_exec()
|
||||
|
Loading…
Reference in New Issue
Block a user