diff options
Diffstat (limited to 'lib/wchar.c')
-rw-r--r-- | lib/wchar.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/wchar.c b/lib/wchar.c index b2e9e7545b..250538dd85 100644 --- a/lib/wchar.c +++ b/lib/wchar.c @@ -3,9 +3,6 @@ * * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix * - * See file CREDITS for list of people who contributed to this - * project. - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. @@ -31,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); @@ -47,12 +53,30 @@ wchar_t *strdup_wchar(const wchar_t *src) return tmp; } +int mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + if (!s) + return 0; /* we don't mantain a non-trivial shift state */ + + if (n < 1) + return -1; + + *pwc = *s; + return 1; +} + +int wctomb(char *s, wchar_t wc) +{ + *s = wc & 0xFF; + return 1; +} + char *strcpy_wchar_to_char(char *dst, const wchar_t *src) { char *ret = dst; while (*src) - *dst++ = *src++ & 0xff; + wctomb(dst++, *src++); *dst = 0; @@ -64,7 +88,7 @@ wchar_t *strcpy_char_to_wchar(wchar_t *dst, const char *src) wchar_t *ret = dst; while (*src) - *dst++ = *src++; + mbtowc(dst++, src++, 1); *dst = 0; |