summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-07-04 09:04:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-07-14 08:01:06 +0200
commit2e82822d080950d9f2cc2bfadafd31ec9809b871 (patch)
tree8ebec3665e92e6bb95cd1268f4b85c5083192b03 /lib
parent9b09369a0a118282eff1b953f82de66e220ee22a (diff)
downloadbarebox-2e82822d080950d9f2cc2bfadafd31ec9809b871.tar.gz
barebox-2e82822d080950d9f2cc2bfadafd31ec9809b871.tar.xz
Add beginning wchar support
EFI uses 16 bit character strings. Add beginning support for this. Since barebox uses 8 bit strings internally we need conversion functions to convert between 16 bit and 8 bit strings. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile1
-rw-r--r--lib/misc.c1
-rw-r--r--lib/wchar.c80
3 files changed, 82 insertions, 0 deletions
diff --git a/lib/Makefile b/lib/Makefile
index e8769a9be2..48c953d679 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -44,3 +44,4 @@ obj-y += gui/
obj-$(CONFIG_XYMODEM) += xymodem.o
obj-y += unlink-recursive.o
obj-$(CONFIG_STMP_DEVICE) += stmp-device.o
+obj-y += wchar.o
diff --git a/lib/misc.c b/lib/misc.c
index 9f2067cf36..87626c1e8b 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -21,6 +21,7 @@
#include <malloc.h>
#include <errno.h>
#include <fs.h>
+#include <string.h>
#include <linux/ctype.h>
/*
diff --git a/lib/wchar.c b/lib/wchar.c
new file mode 100644
index 0000000000..6368a01994
--- /dev/null
+++ b/lib/wchar.c
@@ -0,0 +1,80 @@
+/*
+ * wchar.c - wide character support
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <wchar.h>
+#include <malloc.h>
+#include <string.h>
+
+size_t wcslen(const wchar_t *s)
+{
+ size_t len = 0;
+
+ while (*s++)
+ len++;
+
+ return len;
+}
+
+char *strcpy_wchar_to_char(char *dst, const wchar_t *src)
+{
+ char *ret = dst;
+
+ while (*src)
+ *dst++ = *src++ & 0xff;
+
+ *dst = 0;
+
+ return ret;
+}
+
+wchar_t *strcpy_char_to_wchar(wchar_t *dst, const char *src)
+{
+ wchar_t *ret = dst;
+
+ while (*src)
+ *dst++ = *src++;
+
+ *dst = 0;
+
+ return ret;
+}
+
+wchar_t *strdup_char_to_wchar(const char *src)
+{
+ wchar_t *dst = malloc((strlen(src) + 1) * sizeof(wchar_t));
+
+ if (!dst)
+ return NULL;
+
+ strcpy_char_to_wchar(dst, src);
+
+ return dst;
+}
+
+char *strdup_wchar_to_char(const wchar_t *src)
+{
+ char *dst = malloc((wcslen(src) + 1));
+
+ if (!dst)
+ return NULL;
+
+ strcpy_wchar_to_char(dst, src);
+
+ return dst;
+}