mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 09/21] Add beginning wchar support
Date: Tue,  8 Jul 2014 10:50:05 +0200	[thread overview]
Message-ID: <1404809417-21477-10-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1404809417-21477-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 include/wchar.h | 16 ++++++++++++
 lib/Makefile    |  1 +
 lib/misc.c      |  1 +
 lib/wchar.c     | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 include/wchar.h
 create mode 100644 lib/wchar.c

diff --git a/include/wchar.h b/include/wchar.h
new file mode 100644
index 0000000..278a189
--- /dev/null
+++ b/include/wchar.h
@@ -0,0 +1,16 @@
+#ifndef __WCHAR_H
+#define __WCHAR_H
+
+#include <linux/types.h>
+
+typedef u16 wchar_t;
+
+char *strcpy_wchar_to_char(char *dst, const wchar_t *src);
+
+wchar_t *strcpy_char_to_wchar(wchar_t *dst, const char *src);
+
+wchar_t *strdup_char_to_wchar(const char *src);
+
+char *strdup_wchar_to_char(const wchar_t *src);
+
+#endif /* __WCHAR_H */
diff --git a/lib/Makefile b/lib/Makefile
index e8769a9..48c953d 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 9f2067c..87626c1 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 0000000..6368a01
--- /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;
+}
-- 
2.0.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-07-08  8:50 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-08  8:49 Initial EFI Support Sascha Hauer
2014-07-08  8:49 ` [PATCH 01/21] Make IPaddr_t a 32bit type Sascha Hauer
2014-07-08  8:49 ` [PATCH 02/21] oftree command: Use size_t for size Sascha Hauer
2014-07-08  8:49 ` [PATCH 03/21] fat: Use correct format specifier Sascha Hauer
2014-07-08  8:50 ` [PATCH 04/21] readkey: keys are unsugned char Sascha Hauer
2014-07-08  8:50 ` [PATCH 05/21] of: platform: Use PRINTF_CONVERSION_RESOURCE for printing resources Sascha Hauer
2014-07-08  8:50 ` [PATCH 06/21] console: Add puts callback to console devices Sascha Hauer
2014-07-08  8:50 ` [PATCH 07/21] Add hex_byte_pack and hex_byte_pack_upper from kernel Sascha Hauer
2014-07-08  8:50 ` [PATCH 08/21] vsprintf: Support pU for printing UUIDs Sascha Hauer
2014-07-08  8:50 ` Sascha Hauer [this message]
2014-07-11 12:35   ` [PATCH 09/21] Add beginning wchar support Antony Pavlov
2014-07-14  6:05     ` Sascha Hauer
2014-07-08  8:50 ` [PATCH 10/21] block: Add flush callback Sascha Hauer
2014-07-08  8:50 ` [PATCH 11/21] Move efi.h to include/ Sascha Hauer
2014-07-08  8:50 ` [PATCH 12/21] filetype: Add DOS EXE file detection support Sascha Hauer
2014-07-08  8:50 ` [PATCH 13/21] efi: Add more error codes Sascha Hauer
2014-07-08  8:50 ` [PATCH 14/21] serial: ns16550: Add mmiobase to private data Sascha Hauer
2014-07-08  8:50 ` [PATCH 15/21] serial: ns16550: Add register read/write function pointers " Sascha Hauer
2014-07-08  8:50 ` [PATCH 16/21] Documentation: Add EFI documentation Sascha Hauer
2014-07-08  9:04   ` Jean-Christophe PLAGNIOL-VILLARD
2014-07-08  8:50 ` [PATCH 17/21] Add initial EFI architecture support Sascha Hauer
2014-07-08  8:50 ` [PATCH 18/21] net: Add EFI Simple Network Protocol Driver Sascha Hauer
2014-07-08  8:50 ` [PATCH 19/21] serial: Add EFI stdio driver Sascha Hauer
2014-07-08  8:50 ` [PATCH 20/21] fs: implement EFI filesystem driver Sascha Hauer
2014-07-08  8:50 ` [PATCH 21/21] fs: implement EFI variable " Sascha Hauer
2014-07-08  8:53 ` Initial EFI Support Jean-Christophe PLAGNIOL-VILLARD
2014-07-08  8:59   ` Sascha Hauer
2014-07-08  9:52     ` Sascha Hauer
2014-07-08 10:04 ` Jean-Christophe PLAGNIOL-VILLARD
2014-07-08 16:38 ` [PATCH 1/2] EFI: enable printf UUID support Jean-Christophe PLAGNIOL-VILLARD
2014-07-08 16:38   ` [PATCH 2/2] EFI: introduce efi_strguid to convert GUID to human readable names Jean-Christophe PLAGNIOL-VILLARD
2014-07-11  7:23     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404809417-21477-10-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox