From: Ahmad Fatoum <a.fat...@pengutronix.de> For use by the EFI code, implement string comparison for wide character strings.
Signed-off-by: Ahmad Fatoum <a.fat...@barebox.org> --- include/wchar.h | 3 +++ lib/wchar.c | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/wchar.h b/include/wchar.h index 392211039a61..02818815e183 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -24,4 +24,7 @@ size_t wcsnlen(const wchar_t *s, size_t maxlen); int mbtowc(wchar_t *pwc, const char *s, size_t n); int wctomb(char *s, wchar_t wc); +int wcscmp (const wchar_t *s1, const wchar_t *s2); +int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n); + #endif /* __WCHAR_H */ diff --git a/lib/wchar.c b/lib/wchar.c index 49e946a09424..96db8116286a 100644 --- a/lib/wchar.c +++ b/lib/wchar.c @@ -124,3 +124,29 @@ char *strdup_wchar_to_char(const wchar_t *src) return dst; } + +int wcscmp(const wchar_t *s1, const wchar_t *s2) +{ + while (*s1 == *s2++) { + if (*s1++ == 0) + return 0; + } + + return *s1 - *--s2; +} + +int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n) +{ + if (n == 0) + return 0; + + do { + if (*s1 != *s2++) + return *s1 - *--s2; + + if (*s1++ == 0) + break; + } while (--n != 0); + + return 0; +} -- 2.39.5