aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 4365df31a1d5..d7222a9c8267 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -31,13 +31,10 @@
31#include <asm/div64.h> 31#include <asm/div64.h>
32#include <asm/sections.h> /* for dereference_function_descriptor() */ 32#include <asm/sections.h> /* for dereference_function_descriptor() */
33 33
34/* Works only for digits and letters, but small and fast */
35#define TOLOWER(x) ((x) | 0x20)
36
37static unsigned int simple_guess_base(const char *cp) 34static unsigned int simple_guess_base(const char *cp)
38{ 35{
39 if (cp[0] == '0') { 36 if (cp[0] == '0') {
40 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2])) 37 if (_tolower(cp[1]) == 'x' && isxdigit(cp[2]))
41 return 16; 38 return 16;
42 else 39 else
43 return 8; 40 return 8;
@@ -59,13 +56,13 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas
59 if (!base) 56 if (!base)
60 base = simple_guess_base(cp); 57 base = simple_guess_base(cp);
61 58
62 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') 59 if (base == 16 && cp[0] == '0' && _tolower(cp[1]) == 'x')
63 cp += 2; 60 cp += 2;
64 61
65 while (isxdigit(*cp)) { 62 while (isxdigit(*cp)) {
66 unsigned int value; 63 unsigned int value;
67 64
68 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; 65 value = isdigit(*cp) ? *cp - '0' : _tolower(*cp) - 'a' + 10;
69 if (value >= base) 66 if (value >= base)
70 break; 67 break;
71 result = result * base + value; 68 result = result * base + value;
@@ -1036,8 +1033,8 @@ precision:
1036qualifier: 1033qualifier:
1037 /* get the conversion qualifier */ 1034 /* get the conversion qualifier */
1038 spec->qualifier = -1; 1035 spec->qualifier = -1;
1039 if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || 1036 if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
1040 TOLOWER(*fmt) == 'z' || *fmt == 't') { 1037 _tolower(*fmt) == 'z' || *fmt == 't') {
1041 spec->qualifier = *fmt++; 1038 spec->qualifier = *fmt++;
1042 if (unlikely(spec->qualifier == *fmt)) { 1039 if (unlikely(spec->qualifier == *fmt)) {
1043 if (spec->qualifier == 'l') { 1040 if (spec->qualifier == 'l') {
@@ -1104,7 +1101,7 @@ qualifier:
1104 spec->type = FORMAT_TYPE_LONG; 1101 spec->type = FORMAT_TYPE_LONG;
1105 else 1102 else
1106 spec->type = FORMAT_TYPE_ULONG; 1103 spec->type = FORMAT_TYPE_ULONG;
1107 } else if (TOLOWER(spec->qualifier) == 'z') { 1104 } else if (_tolower(spec->qualifier) == 'z') {
1108 spec->type = FORMAT_TYPE_SIZE_T; 1105 spec->type = FORMAT_TYPE_SIZE_T;
1109 } else if (spec->qualifier == 't') { 1106 } else if (spec->qualifier == 't') {
1110 spec->type = FORMAT_TYPE_PTRDIFF; 1107 spec->type = FORMAT_TYPE_PTRDIFF;
@@ -1149,8 +1146,7 @@ qualifier:
1149 * %pi4 print an IPv4 address with leading zeros 1146 * %pi4 print an IPv4 address with leading zeros
1150 * %pI6 print an IPv6 address with colons 1147 * %pI6 print an IPv6 address with colons
1151 * %pi6 print an IPv6 address without colons 1148 * %pi6 print an IPv6 address without colons
1152 * %pI6c print an IPv6 address as specified by 1149 * %pI6c print an IPv6 address as specified by RFC 5952
1153 * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00
1154 * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper 1150 * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
1155 * case. 1151 * case.
1156 * %n is ignored 1152 * %n is ignored
@@ -1263,7 +1259,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1263 if (qualifier == 'l') { 1259 if (qualifier == 'l') {
1264 long *ip = va_arg(args, long *); 1260 long *ip = va_arg(args, long *);
1265 *ip = (str - buf); 1261 *ip = (str - buf);
1266 } else if (TOLOWER(qualifier) == 'z') { 1262 } else if (_tolower(qualifier) == 'z') {
1267 size_t *ip = va_arg(args, size_t *); 1263 size_t *ip = va_arg(args, size_t *);
1268 *ip = (str - buf); 1264 *ip = (str - buf);
1269 } else { 1265 } else {
@@ -1550,7 +1546,7 @@ do { \
1550 void *skip_arg; 1546 void *skip_arg;
1551 if (qualifier == 'l') 1547 if (qualifier == 'l')
1552 skip_arg = va_arg(args, long *); 1548 skip_arg = va_arg(args, long *);
1553 else if (TOLOWER(qualifier) == 'z') 1549 else if (_tolower(qualifier) == 'z')
1554 skip_arg = va_arg(args, size_t *); 1550 skip_arg = va_arg(args, size_t *);
1555 else 1551 else
1556 skip_arg = va_arg(args, int *); 1552 skip_arg = va_arg(args, int *);
@@ -1856,8 +1852,8 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
1856 1852
1857 /* get conversion qualifier */ 1853 /* get conversion qualifier */
1858 qualifier = -1; 1854 qualifier = -1;
1859 if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || 1855 if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
1860 TOLOWER(*fmt) == 'z') { 1856 _tolower(*fmt) == 'z') {
1861 qualifier = *fmt++; 1857 qualifier = *fmt++;
1862 if (unlikely(qualifier == *fmt)) { 1858 if (unlikely(qualifier == *fmt)) {
1863 if (qualifier == 'h') { 1859 if (qualifier == 'h') {