diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-09-19 12:48:04 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-03 11:13:50 +0000 |
commit | 3c807402b3491ccf94af5f4da8394bbd3ff91977 (patch) | |
tree | 9bfc465e6a4965497e93ae16383e7f1bd2da2bcd /Userland/Libraries/LibC/wchar.cpp | |
parent | ab46864674f2df8f518479a12009e99939bdc68e (diff) | |
download | serenity-3c807402b3491ccf94af5f4da8394bbd3ff91977.zip |
LibC: Remove the mbstate_reset helper
A zero-initialized mbstate_t struct has to be a valid initial state, so
we can just zero-initialize it whenever we need to reset.
Having a helper function for resetting the struct might imply that you
can add additional setup operations afterwards, which is not the case.
Diffstat (limited to 'Userland/Libraries/LibC/wchar.cpp')
-rw-r--r-- | Userland/Libraries/LibC/wchar.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/Userland/Libraries/LibC/wchar.cpp b/Userland/Libraries/LibC/wchar.cpp index aff52acd84..eb8242fd53 100644 --- a/Userland/Libraries/LibC/wchar.cpp +++ b/Userland/Libraries/LibC/wchar.cpp @@ -9,11 +9,6 @@ #include <errno.h> #include <wchar.h> -static void mbstate_reset(mbstate_t* state) -{ - *state = { 0 }; -} - static unsigned int mbstate_stored_bytes(mbstate_t* state) { for (unsigned int i = 0; i < sizeof(state->bytes); i++) { @@ -215,7 +210,7 @@ wint_t btowc(int c) size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state) { - static mbstate_t _anonymous_state = { 0 }; + static mbstate_t _anonymous_state = {}; if (state == nullptr) { state = &_anonymous_state; @@ -224,10 +219,10 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state) // If s is nullptr, check if the state contains a complete multibyte character if (s == nullptr) { if (mbstate_expected_bytes(state) == mbstate_stored_bytes(state)) { - mbstate_reset(state); + *state = {}; return 0; } else { - mbstate_reset(state); + *state = {}; errno = EILSEQ; return -1; } @@ -251,7 +246,7 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state) // Check if the first byte is invalid if (expected_bytes == 0) { - mbstate_reset(state); + *state = {}; errno = EILSEQ; return -1; } @@ -269,7 +264,7 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state) // Continuation bytes have to start with 0b10xxxxxx if ((c & 0b11000000) != 0b10000000) { // Invalid multibyte character - mbstate_reset(state); + *state = {}; errno = EILSEQ; return -1; } @@ -296,7 +291,7 @@ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* state) } // We don't have a shift state that we need to keep, so just clear the entire state - mbstate_reset(state); + *state = {}; if (codepoint == 0) { return 0; |