From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] vsprintf.c: add wide string (%ls) support
Date: Mon, 31 Jul 2017 08:42:02 -0400 [thread overview]
Message-ID: <20170731124202.9500-2-robdclark@gmail.com> (raw)
In-Reply-To: <20170731124202.9500-1-robdclark@gmail.com>
This is convenient for efi_loader which deals a lot with utf16.
Signed-off-by: Rob Clark <robdclark@gmail.com>
---
lib/vsprintf.c | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 874a2951f7..84e157ecb1 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -270,6 +270,35 @@ static char *string(char *buf, char *end, char *s, int field_width,
return buf;
}
+static size_t strnlen16(const u16* s, size_t count)
+{
+ const u16 *sc;
+
+ for (sc = s; count-- && *sc; ++sc)
+ /* nothing */;
+ return sc - s;
+}
+
+static char *string16(char *buf, char *end, u16 *s, int field_width,
+ int precision, int flags)
+{
+ int len, i;
+
+ if (s == NULL)
+ s = L"<NULL>";
+
+ len = strnlen16(s, precision);
+
+ if (!(flags & LEFT))
+ while (len < field_width--)
+ ADDCH(buf, ' ');
+ for (i = 0; i < len; ++i)
+ ADDCH(buf, *s++);
+ while (len < field_width--)
+ ADDCH(buf, ' ');
+ return buf;
+}
+
#ifdef CONFIG_CMD_NET
static const char hex_asc[] = "0123456789abcdef";
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
@@ -528,8 +557,14 @@ repeat:
continue;
case 's':
- str = string(str, end, va_arg(args, char *),
- field_width, precision, flags);
+ if (qualifier == 'l') {
+ str = string16(str, end, va_arg(args, u16 *),
+ field_width, precision, flags);
+
+ } else {
+ str = string(str, end, va_arg(args, char *),
+ field_width, precision, flags);
+ }
continue;
case 'p':
--
2.13.0
next prev parent reply other threads:[~2017-07-31 12:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-31 12:42 [U-Boot] [PATCH] env: add ENV_IS_ANYWHERE Rob Clark
2017-07-31 12:42 ` Rob Clark [this message]
2017-08-02 2:22 ` [U-Boot] [PATCH] vsprintf.c: add wide string (%ls) support Heinrich Schuchardt
2017-08-02 9:38 ` Rob Clark
2017-08-02 17:05 ` Heinrich Schuchardt
2017-08-02 18:15 ` Rob Clark
2017-08-02 21:40 ` Heinrich Schuchardt
2017-08-02 22:25 ` Rob Clark
2017-08-03 0:48 ` [U-Boot] [PATCH] env: add ENV_IS_ANYWHERE Tom Rini
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=20170731124202.9500-2-robdclark@gmail.com \
--to=robdclark@gmail.com \
--cc=u-boot@lists.denx.de \
/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