diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-08-07 06:14:56 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-08-07 06:14:56 +0200 |
commit | 8a11a59b379b641423a6ed655aae36ec00404403 (patch) | |
tree | a10f059d0bdcf9ba043cef744d605f9260991b18 /lib | |
parent | e3ff4dfa41b4e8afc26b69e5c3d8c127f0f37c39 (diff) | |
parent | 9183a8c683014f7f6dae004009556c9c0d4d2a15 (diff) | |
download | barebox-8a11a59b379b641423a6ed655aae36ec00404403.tar.gz barebox-8a11a59b379b641423a6ed655aae36ec00404403.tar.xz |
Merge branch 'for-next/efi'
Conflicts:
.gitignore
Makefile
drivers/serial/Makefile
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 3 | ||||
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/misc.c | 3 | ||||
-rw-r--r-- | lib/readkey.c | 2 | ||||
-rw-r--r-- | lib/vsprintf.c | 62 | ||||
-rw-r--r-- | lib/wchar.c | 80 |
6 files changed, 150 insertions, 1 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index d9ad4aa949..09a1674820 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -54,4 +54,7 @@ source lib/gui/Kconfig source lib/bootstrap/Kconfig +config PRINTF_UUID + bool + endmenu 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 0f3eb9aabb..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> /* @@ -113,3 +114,5 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size) return -1; } EXPORT_SYMBOL(parse_area_spec); + +const char hex_asc[] = "0123456789abcdef"; diff --git a/lib/readkey.c b/lib/readkey.c index 7b38110113..2073a732f4 100644 --- a/lib/readkey.c +++ b/lib/readkey.c @@ -25,7 +25,7 @@ struct esc_cmds { const char *seq; - char val; + unsigned char val; }; static const struct esc_cmds esccmds[] = { diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 066338b4e8..512c88247f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -253,6 +253,53 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int #endif } +static noinline_for_stack +char *uuid_string(char *buf, char *end, const u8 *addr, int field_width, + int precision, int flags, const char *fmt) +{ + char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; + char *p = uuid; + int i; + static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; + const u8 *index = be; + bool uc = false; + + switch (*(++fmt)) { + case 'L': + uc = true; /* fall-through */ + case 'l': + index = le; + break; + case 'B': + uc = true; + break; + } + + for (i = 0; i < 16; i++) { + p = hex_byte_pack(p, addr[index[i]]); + switch (i) { + case 3: + case 5: + case 7: + case 9: + *p++ = '-'; + break; + } + } + + *p = 0; + + if (uc) { + p = uuid; + do { + *p = toupper(*p); + } while (*(++p)); + } + + return string(buf, end, uuid, field_width, precision, flags); +} + /* * Show a '%p' thing. A kernel extension is that the '%p' is followed * by an extra set of alphanumeric characters that are extended format @@ -261,6 +308,17 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int * Right now we handle: * * - 'S' For symbolic direct pointers + * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form + * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + * Options for %pU are: + * b big endian lower case hex (default) + * B big endian UPPER case hex + * l little endian lower case hex + * L little endian UPPER case hex + * big endian output byte order is: + * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] + * little endian output byte order is: + * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] * * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 * function pointers are really function descriptors, which contain a @@ -271,6 +329,10 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field switch (*fmt) { case 'S': return symbol_string(buf, end, ptr, field_width, precision, flags); + case 'U': + if (IS_ENABLED(CONFIG_PRINTF_UUID)) + return uuid_string(buf, end, ptr, field_width, precision, flags, fmt); + break; } flags |= SMALL; if (field_width == -1) { 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; +} |