libc: Flush buffers before dealing with file positions

This commit is contained in:
apio 2023-07-22 11:19:48 +02:00
parent 420270ebd4
commit 19b4aa9f81
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -350,6 +350,8 @@ extern "C"
int fseek(FILE* stream, long offset, int whence)
{
fflush(stream);
long result = lseek(stream->_fd, offset, whence);
if (result < 0) return -1;
@ -361,11 +363,15 @@ extern "C"
long ftell(FILE* stream)
{
fflush(stream);
return lseek(stream->_fd, 0, SEEK_CUR);
}
void rewind(FILE* stream)
{
fflush(stream);
lseek(stream->_fd, 0, SEEK_SET);
clearerr(stream);
@ -383,6 +389,8 @@ extern "C"
int fsetpos(FILE* stream, const fpos_t* pos)
{
fflush(stream);
return fseek(stream, *pos, SEEK_SET);
}