mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibC: Implement mbrtowc closer to POSIX
This commit is contained in:
parent
e7f99edefa
commit
4ef3ed4ba3
1 changed files with 5 additions and 9 deletions
|
@ -209,16 +209,11 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state)
|
||||||
state = &_anonymous_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 (s == nullptr) {
|
||||||
if (mbstate_expected_bytes(state) == mbstate->stored_bytes) {
|
pwc = nullptr;
|
||||||
*state = {};
|
s = "";
|
||||||
return 0;
|
n = 1;
|
||||||
} else {
|
|
||||||
*state = {};
|
|
||||||
errno = EILSEQ;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop early if we can't read anything
|
// 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;
|
state->stored_bytes = 0;
|
||||||
|
|
||||||
if (codepoint == 0) {
|
if (codepoint == 0) {
|
||||||
|
*state = {};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue