1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

LibC: Implement {f,}putwc()

This commit is contained in:
Ali Mohammad Pur 2021-12-20 16:08:03 +03:30 committed by Ali Mohammad Pur
parent a4e8a09188
commit cb90856756
4 changed files with 40 additions and 1 deletions

View file

@ -5,6 +5,7 @@
*/
#include <AK/Assertions.h>
#include <AK/BitCast.h>
#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <bits/stdio_file_implementation.h>
@ -61,4 +62,34 @@ wint_t getwchar()
{
return getwc(stdin);
}
wint_t fputwc(wchar_t wc, FILE* stream)
{
VERIFY(stream);
// Negative wide chars are weird
if constexpr (IsSigned<wchar_t>) {
if (wc < 0) {
errno = EILSEQ;
return WEOF;
}
}
StringBuilder sb;
sb.append_code_point(static_cast<u32>(wc));
auto bytes = sb.string_view().bytes();
ScopedFileLock lock(stream);
size_t nwritten = stream->write(bytes.data(), bytes.size());
if (nwritten < bytes.size())
return WEOF;
return wc;
}
wint_t putwc(wchar_t wc, FILE* stream)
{
return fputwc(wc, stream);
}
wint_t putwchar(wchar_t wc)
{
return fputwc(wc, stdout);
}
}