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 | |
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')
-rw-r--r-- | Userland/Libraries/LibC/wchar.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibC/wchar.h | 1 |
2 files changed, 7 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; diff --git a/Userland/Libraries/LibC/wchar.h b/Userland/Libraries/LibC/wchar.h index 557217b454..cb15c3f3ff 100644 --- a/Userland/Libraries/LibC/wchar.h +++ b/Userland/Libraries/LibC/wchar.h @@ -18,6 +18,7 @@ __BEGIN_DECLS typedef __WINT_TYPE__ wint_t; typedef unsigned long int wctype_t; +// A zero-initialized mbstate_t struct must be a valid initial state. typedef struct { unsigned char bytes[4]; } mbstate_t; |