summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2021-09-21 21:28:53 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-10-03 11:13:50 +0000
commit4ef3ed4ba3c816203adb2f7c57f1b1d1bce16589 (patch)
tree62932b51985243170dedafc619e8855cb5e30d44 /Userland/Libraries/LibC
parente7f99edefa50b1014880d44b4683e5570a05f987 (diff)
downloadserenity-4ef3ed4ba3c816203adb2f7c57f1b1d1bce16589.zip
LibC: Implement mbrtowc closer to POSIX
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/wchar.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/Userland/Libraries/LibC/wchar.cpp b/Userland/Libraries/LibC/wchar.cpp
index bf2f855b14..db8e5838c5 100644
--- a/Userland/Libraries/LibC/wchar.cpp
+++ b/Userland/Libraries/LibC/wchar.cpp
@@ -209,16 +209,11 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state)
state = &_anonymous_state;
}
- // If s is nullptr, check if the state contains a complete multibyte character
+ // s being a null pointer is a shorthand for reading a single null byte.
if (s == nullptr) {
- if (mbstate_expected_bytes(state) == mbstate->stored_bytes) {
- *state = {};
- return 0;
- } else {
- *state = {};
- errno = EILSEQ;
- return -1;
- }
+ pwc = nullptr;
+ s = "";
+ n = 1;
}
// Stop early if we can't read anything
@@ -284,6 +279,7 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state)
state->stored_bytes = 0;
if (codepoint == 0) {
+ *state = {};
return 0;
}