[PATCH 06/10] lib: add wchar strdup

Lucas Stach l.stach at pengutronix.de
Tue Nov 4 01:42:52 PST 2014


Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
---
 include/wchar.h |  2 ++
 lib/wchar.c     | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/wchar.h b/include/wchar.h
index 80dcd81bf442..702d8e239a7c 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -5,6 +5,8 @@
 
 typedef u16 wchar_t;
 
+wchar_t *strdup_wchar(const wchar_t *src);
+
 char *strcpy_wchar_to_char(char *dst, const wchar_t *src);
 
 wchar_t *strcpy_char_to_wchar(wchar_t *dst, const char *src);
diff --git a/lib/wchar.c b/lib/wchar.c
index 6368a019941e..b2e9e7545b1f 100644
--- a/lib/wchar.c
+++ b/lib/wchar.c
@@ -31,6 +31,22 @@ size_t wcslen(const wchar_t *s)
 	return len;
 }
 
+wchar_t *strdup_wchar(const wchar_t *src)
+{
+	int len = wcslen(src);
+	wchar_t *tmp, *dst;
+
+	if (!(dst = malloc((len + 1) * sizeof(wchar_t))))
+		return NULL;
+
+	tmp = dst;
+
+	while ((*dst++ = *src++))
+		/* nothing */;
+
+	return tmp;
+}
+
 char *strcpy_wchar_to_char(char *dst, const wchar_t *src)
 {
 	char *ret = dst;
-- 
2.1.1




More information about the barebox mailing list