[PATCH 01/15] lib: wchar: add wide char string comparison functions
Ahmad Fatoum
a.fatoum at barebox.org
Tue May 27 14:22:46 PDT 2025
From: Ahmad Fatoum <a.fatoum at pengutronix.de>
For use by the EFI code, implement string comparison for wide character
strings.
Signed-off-by: Ahmad Fatoum <a.fatoum at 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
More information about the barebox
mailing list