libc: Implement ungetc
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2023-07-22 11:25:20 +02:00
parent 19b4aa9f81
commit 77022abafd
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -688,9 +688,18 @@ extern "C"
return f; return f;
} }
int ungetc(int, FILE*) int ungetc(int c, FILE* stream)
{ {
fail("FIXME: ungetc: not implemented"); if (stream->_buf.index == 0)
return EOF; // No data currently in the read buffer, or no data has been read from it.
if (stream->_buf.mode == _IONBF)
return EOF; // FIXME: C doesn't state that ungetc() should only work on buffered streams.
stream->_buf.index--;
stream->_buf.buffer[stream->_buf.index] = (char)c;
return 0;
} }
int setvbuf(FILE* stream, char* buf, int mode, size_t size) int setvbuf(FILE* stream, char* buf, int mode, size_t size)