[PATCH 18/30] lib: implement wcsnlen
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Nov 22 00:47:20 PST 2021
This will come in handy for implementing %ls in the follow up commit.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
include/wchar.h | 2 ++
lib/wchar.c | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/include/wchar.h b/include/wchar.h
index fb9b127a8c04..392211039a61 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -17,6 +17,8 @@ char *strdup_wchar_to_char(const wchar_t *src);
size_t wcslen(const wchar_t *s);
+size_t wcsnlen(const wchar_t *s, size_t maxlen);
+
#define MB_CUR_MAX 4
int mbtowc(wchar_t *pwc, const char *s, size_t n);
diff --git a/lib/wchar.c b/lib/wchar.c
index 3be228b5a77a..250538dd8511 100644
--- a/lib/wchar.c
+++ b/lib/wchar.c
@@ -28,6 +28,15 @@ size_t wcslen(const wchar_t *s)
return len;
}
+size_t wcsnlen(const wchar_t * s, size_t count)
+{
+ const wchar_t *sc;
+
+ for (sc = s; count-- && *sc != L'\0'; ++sc)
+ /* nothing */;
+ return sc - s;
+}
+
wchar_t *strdup_wchar(const wchar_t *src)
{
int len = wcslen(src);
--
2.30.2
More information about the barebox
mailing list