diff options
author | Lucas Stach <l.stach@pengutronix.de> | 2014-12-08 14:42:35 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-12-09 09:59:10 +0100 |
commit | 42c8b4589a9bd021df7bc6d52dd603dbf99164e5 (patch) | |
tree | 279150521e9222eb91dc07fcf213c41b99a6f952 | |
parent | 26793cc2cc75a29dd9924b0e53cbc2a7c77996bd (diff) | |
download | barebox-42c8b4589a9bd021df7bc6d52dd603dbf99164e5.tar.gz barebox-42c8b4589a9bd021df7bc6d52dd603dbf99164e5.tar.xz |
lib: add wchar strdup
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | include/wchar.h | 2 | ||||
-rw-r--r-- | lib/wchar.c | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/wchar.h b/include/wchar.h index 80dcd81bf4..702d8e239a 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 6368a01994..b2e9e7545b 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; |