libc: Reset the read buffer even when read() returns an error

This fixes the same data being read multiple times if an error was returned
This commit is contained in:
apio 2023-08-08 10:39:15 +02:00
parent 7c254e5e15
commit 198935eb30
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -135,6 +135,8 @@ static ssize_t read_data_into_buffer(FILE* stream)
stream->_buf.index = 0;
ssize_t nread = read(stream->_fd, stream->_buf.buffer, stream->_buf.capacity);
if (nread >= 0) stream->_buf.size = nread;
else
stream->_buf.size = 0;
stream->_buf.status |= FileStatusFlags::LastRead;
return nread;
}