1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibC: Implement ungetwc()

This commit is contained in:
Ali Mohammad Pur 2021-12-19 23:29:21 +03:30 committed by Ali Mohammad Pur
parent 14b91a3fe9
commit e717ca32d1
7 changed files with 63 additions and 18 deletions

View file

@ -120,6 +120,25 @@ int fputws(wchar_t const* __restrict ws, FILE* __restrict stream)
return size;
}
wint_t ungetwc(wint_t wc, FILE* stream)
{
VERIFY(stream);
ScopedFileLock lock(stream);
StringBuilder sb;
sb.append_code_point(static_cast<u32>(wc));
auto bytes = sb.string_view().bytes();
size_t ok_bytes = 0;
for (auto byte : bytes) {
if (!stream->ungetc(byte)) {
// Discard the half-ungotten bytes.
stream->read(const_cast<u8*>(bytes.data()), ok_bytes);
return WEOF;
}
++ok_bytes;
}
return wc;
}
int wprintf(wchar_t const* __restrict format, ...)
{
va_list ap;