Commit 7b9186f5 authored by André Goddard Rosa's avatar André Goddard Rosa Committed by Linus Torvalds

vsprintf: give it some care to please checkpatch.pl

Most relevant complaints were addressed.
Signed-off-by: default avatarAndré Goddard Rosa <andre.goddard@gmail.com>
Acked-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6c356634
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Wirzenius wrote this portably, Torvalds fucked it up :-) * Wirzenius wrote this portably, Torvalds fucked it up :-)
*/ */
/* /*
* Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com>
* - changed to provide snprintf and vsnprintf functions * - changed to provide snprintf and vsnprintf functions
* So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de> * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de>
...@@ -71,9 +71,9 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) ...@@ -71,9 +71,9 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
result = result * base + value; result = result * base + value;
cp++; cp++;
} }
if (endp) if (endp)
*endp = (char *)cp; *endp = (char *)cp;
return result; return result;
} }
EXPORT_SYMBOL(simple_strtoul); EXPORT_SYMBOL(simple_strtoul);
...@@ -86,8 +86,9 @@ EXPORT_SYMBOL(simple_strtoul); ...@@ -86,8 +86,9 @@ EXPORT_SYMBOL(simple_strtoul);
*/ */
long simple_strtol(const char *cp, char **endp, unsigned int base) long simple_strtol(const char *cp, char **endp, unsigned int base)
{ {
if(*cp == '-') if (*cp == '-')
return -simple_strtoul(cp + 1, endp, base); return -simple_strtoul(cp + 1, endp, base);
return simple_strtoul(cp, endp, base); return simple_strtoul(cp, endp, base);
} }
EXPORT_SYMBOL(simple_strtol); EXPORT_SYMBOL(simple_strtol);
...@@ -117,9 +118,9 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas ...@@ -117,9 +118,9 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas
result = result * base + value; result = result * base + value;
cp++; cp++;
} }
if (endp) if (endp)
*endp = (char *)cp; *endp = (char *)cp;
return result; return result;
} }
EXPORT_SYMBOL(simple_strtoull); EXPORT_SYMBOL(simple_strtoull);
...@@ -132,8 +133,9 @@ EXPORT_SYMBOL(simple_strtoull); ...@@ -132,8 +133,9 @@ EXPORT_SYMBOL(simple_strtoull);
*/ */
long long simple_strtoll(const char *cp, char **endp, unsigned int base) long long simple_strtoll(const char *cp, char **endp, unsigned int base)
{ {
if(*cp=='-') if (*cp == '-')
return -simple_strtoull(cp + 1, endp, base); return -simple_strtoull(cp + 1, endp, base);
return simple_strtoull(cp, endp, base); return simple_strtoull(cp, endp, base);
} }
...@@ -173,6 +175,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) ...@@ -173,6 +175,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
val = simple_strtoul(cp, &tail, base); val = simple_strtoul(cp, &tail, base);
if (tail == cp) if (tail == cp)
return -EINVAL; return -EINVAL;
if ((*tail == '\0') || if ((*tail == '\0') ||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
*res = val; *res = val;
...@@ -285,10 +288,11 @@ EXPORT_SYMBOL(strict_strtoll); ...@@ -285,10 +288,11 @@ EXPORT_SYMBOL(strict_strtoll);
static int skip_atoi(const char **s) static int skip_atoi(const char **s)
{ {
int i=0; int i = 0;
while (isdigit(**s)) while (isdigit(**s))
i = i*10 + *((*s)++) - '0'; i = i*10 + *((*s)++) - '0';
return i; return i;
} }
...@@ -302,7 +306,7 @@ static int skip_atoi(const char **s) ...@@ -302,7 +306,7 @@ static int skip_atoi(const char **s)
/* Formats correctly any integer in [0,99999]. /* Formats correctly any integer in [0,99999].
* Outputs from one to five digits depending on input. * Outputs from one to five digits depending on input.
* On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */
static char* put_dec_trunc(char *buf, unsigned q) static char *put_dec_trunc(char *buf, unsigned q)
{ {
unsigned d3, d2, d1, d0; unsigned d3, d2, d1, d0;
d1 = (q>>4) & 0xf; d1 = (q>>4) & 0xf;
...@@ -331,14 +335,15 @@ static char* put_dec_trunc(char *buf, unsigned q) ...@@ -331,14 +335,15 @@ static char* put_dec_trunc(char *buf, unsigned q)
d3 = d3 - 10*q; d3 = d3 - 10*q;
*buf++ = d3 + '0'; /* next digit */ *buf++ = d3 + '0'; /* next digit */
if (q != 0) if (q != 0)
*buf++ = q + '0'; /* most sign. digit */ *buf++ = q + '0'; /* most sign. digit */
} }
} }
} }
return buf; return buf;
} }
/* Same with if's removed. Always emits five digits */ /* Same with if's removed. Always emits five digits */
static char* put_dec_full(char *buf, unsigned q) static char *put_dec_full(char *buf, unsigned q)
{ {
/* BTW, if q is in [0,9999], 8-bit ints will be enough, */ /* BTW, if q is in [0,9999], 8-bit ints will be enough, */
/* but anyway, gcc produces better code with full-sized ints */ /* but anyway, gcc produces better code with full-sized ints */
...@@ -347,14 +352,15 @@ static char* put_dec_full(char *buf, unsigned q) ...@@ -347,14 +352,15 @@ static char* put_dec_full(char *buf, unsigned q)
d2 = (q>>8) & 0xf; d2 = (q>>8) & 0xf;
d3 = (q>>12); d3 = (q>>12);
/* Possible ways to approx. divide by 10 */ /*
/* gcc -O2 replaces multiply with shifts and adds */ * Possible ways to approx. divide by 10
// (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) * gcc -O2 replaces multiply with shifts and adds
// (x * 0x67) >> 10: 1100111 * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386)
// (x * 0x34) >> 9: 110100 - same * (x * 0x67) >> 10: 1100111
// (x * 0x1a) >> 8: 11010 - same * (x * 0x34) >> 9: 110100 - same
// (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) * (x * 0x1a) >> 8: 11010 - same
* (x * 0x0d) >> 7: 1101 - same, shortest code (on i386)
*/
d0 = 6*(d3 + d2 + d1) + (q & 0xf); d0 = 6*(d3 + d2 + d1) + (q & 0xf);
q = (d0 * 0xcd) >> 11; q = (d0 * 0xcd) >> 11;
d0 = d0 - 10*q; d0 = d0 - 10*q;
...@@ -375,10 +381,11 @@ static char* put_dec_full(char *buf, unsigned q) ...@@ -375,10 +381,11 @@ static char* put_dec_full(char *buf, unsigned q)
d3 = d3 - 10*q; d3 = d3 - 10*q;
*buf++ = d3 + '0'; *buf++ = d3 + '0';
*buf++ = q + '0'; *buf++ = q + '0';
return buf; return buf;
} }
/* No inlining helps gcc to use registers better */ /* No inlining helps gcc to use registers better */
static noinline char* put_dec(char *buf, unsigned long long num) static noinline char *put_dec(char *buf, unsigned long long num)
{ {
while (1) { while (1) {
unsigned rem; unsigned rem;
...@@ -448,9 +455,9 @@ static char *number(char *buf, char *end, unsigned long long num, ...@@ -448,9 +455,9 @@ static char *number(char *buf, char *end, unsigned long long num,
spec.flags &= ~ZEROPAD; spec.flags &= ~ZEROPAD;
sign = 0; sign = 0;
if (spec.flags & SIGN) { if (spec.flags & SIGN) {
if ((signed long long) num < 0) { if ((signed long long)num < 0) {
sign = '-'; sign = '-';
num = - (signed long long) num; num = -(signed long long)num;
spec.field_width--; spec.field_width--;
} else if (spec.flags & PLUS) { } else if (spec.flags & PLUS) {
sign = '+'; sign = '+';
...@@ -478,7 +485,9 @@ static char *number(char *buf, char *end, unsigned long long num, ...@@ -478,7 +485,9 @@ static char *number(char *buf, char *end, unsigned long long num,
else if (spec.base != 10) { /* 8 or 16 */ else if (spec.base != 10) { /* 8 or 16 */
int mask = spec.base - 1; int mask = spec.base - 1;
int shift = 3; int shift = 3;
if (spec.base == 16) shift = 4;
if (spec.base == 16)
shift = 4;
do { do {
tmp[i++] = (digits[((unsigned char)num) & mask] | locase); tmp[i++] = (digits[((unsigned char)num) & mask] | locase);
num >>= shift; num >>= shift;
...@@ -493,7 +502,7 @@ static char *number(char *buf, char *end, unsigned long long num, ...@@ -493,7 +502,7 @@ static char *number(char *buf, char *end, unsigned long long num,
/* leading space padding */ /* leading space padding */
spec.field_width -= spec.precision; spec.field_width -= spec.precision;
if (!(spec.flags & (ZEROPAD+LEFT))) { if (!(spec.flags & (ZEROPAD+LEFT))) {
while(--spec.field_width >= 0) { while (--spec.field_width >= 0) {
if (buf < end) if (buf < end)
*buf = ' '; *buf = ' ';
++buf; ++buf;
...@@ -543,6 +552,7 @@ static char *number(char *buf, char *end, unsigned long long num, ...@@ -543,6 +552,7 @@ static char *number(char *buf, char *end, unsigned long long num,
*buf = ' '; *buf = ' ';
++buf; ++buf;
} }
return buf; return buf;
} }
...@@ -572,6 +582,7 @@ static char *string(char *buf, char *end, const char *s, struct printf_spec spec ...@@ -572,6 +582,7 @@ static char *string(char *buf, char *end, const char *s, struct printf_spec spec
*buf = ' '; *buf = ' ';
++buf; ++buf;
} }
return buf; return buf;
} }
...@@ -585,11 +596,13 @@ static char *symbol_string(char *buf, char *end, void *ptr, ...@@ -585,11 +596,13 @@ static char *symbol_string(char *buf, char *end, void *ptr,
sprint_symbol(sym, value); sprint_symbol(sym, value);
else else
kallsyms_lookup(value, NULL, NULL, NULL, sym); kallsyms_lookup(value, NULL, NULL, NULL, sym);
return string(buf, end, sym, spec); return string(buf, end, sym, spec);
#else #else
spec.field_width = 2*sizeof(void *); spec.field_width = 2 * sizeof(void *);
spec.flags |= SPECIAL | SMALL | ZEROPAD; spec.flags |= SPECIAL | SMALL | ZEROPAD;
spec.base = 16; spec.base = 16;
return number(buf, end, value, spec); return number(buf, end, value, spec);
#endif #endif
} }
...@@ -718,22 +731,19 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) ...@@ -718,22 +731,19 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros)
if (i < 3) if (i < 3)
*p++ = '.'; *p++ = '.';
} }
*p = '\0'; *p = '\0';
return p; return p;
} }
static char *ip6_compressed_string(char *p, const char *addr) static char *ip6_compressed_string(char *p, const char *addr)
{ {
int i; int i, j, range;
int j;
int range;
unsigned char zerolength[8]; unsigned char zerolength[8];
int longest = 1; int longest = 1;
int colonpos = -1; int colonpos = -1;
u16 word; u16 word;
u8 hi; u8 hi, lo;
u8 lo;
bool needcolon = false; bool needcolon = false;
bool useIPv4; bool useIPv4;
struct in6_addr in6; struct in6_addr in6;
...@@ -800,22 +810,23 @@ static char *ip6_compressed_string(char *p, const char *addr) ...@@ -800,22 +810,23 @@ static char *ip6_compressed_string(char *p, const char *addr)
*p++ = ':'; *p++ = ':';
p = ip4_string(p, &in6.s6_addr[12], false); p = ip4_string(p, &in6.s6_addr[12], false);
} }
*p = '\0'; *p = '\0';
return p; return p;
} }
static char *ip6_string(char *p, const char *addr, const char *fmt) static char *ip6_string(char *p, const char *addr, const char *fmt)
{ {
int i; int i;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
p = pack_hex_byte(p, *addr++); p = pack_hex_byte(p, *addr++);
p = pack_hex_byte(p, *addr++); p = pack_hex_byte(p, *addr++);
if (fmt[0] == 'I' && i != 7) if (fmt[0] == 'I' && i != 7)
*p++ = ':'; *p++ = ':';
} }
*p = '\0'; *p = '\0';
return p; return p;
} }
...@@ -1322,7 +1333,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -1322,7 +1333,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{ {
int i; int i;
i=vsnprintf(buf,size,fmt,args); i = vsnprintf(buf, size, fmt, args);
return (i >= size) ? (size - 1) : i; return (i >= size) ? (size - 1) : i;
} }
EXPORT_SYMBOL(vscnprintf); EXPORT_SYMBOL(vscnprintf);
...@@ -1341,14 +1353,15 @@ EXPORT_SYMBOL(vscnprintf); ...@@ -1341,14 +1353,15 @@ EXPORT_SYMBOL(vscnprintf);
* *
* See the vsnprintf() documentation for format string extensions over C99. * See the vsnprintf() documentation for format string extensions over C99.
*/ */
int snprintf(char * buf, size_t size, const char *fmt, ...) int snprintf(char *buf, size_t size, const char *fmt, ...)
{ {
va_list args; va_list args;
int i; int i;
va_start(args, fmt); va_start(args, fmt);
i=vsnprintf(buf,size,fmt,args); i = vsnprintf(buf, size, fmt, args);
va_end(args); va_end(args);
return i; return i;
} }
EXPORT_SYMBOL(snprintf); EXPORT_SYMBOL(snprintf);
...@@ -1364,7 +1377,7 @@ EXPORT_SYMBOL(snprintf); ...@@ -1364,7 +1377,7 @@ EXPORT_SYMBOL(snprintf);
* the trailing '\0'. If @size is <= 0 the function returns 0. * the trailing '\0'. If @size is <= 0 the function returns 0.
*/ */
int scnprintf(char * buf, size_t size, const char *fmt, ...) int scnprintf(char *buf, size_t size, const char *fmt, ...)
{ {
va_list args; va_list args;
int i; int i;
...@@ -1372,6 +1385,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) ...@@ -1372,6 +1385,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
i = vsnprintf(buf, size, fmt, args); i = vsnprintf(buf, size, fmt, args);
va_end(args); va_end(args);
return (i >= size) ? (size - 1) : i; return (i >= size) ? (size - 1) : i;
} }
EXPORT_SYMBOL(scnprintf); EXPORT_SYMBOL(scnprintf);
...@@ -1409,14 +1423,15 @@ EXPORT_SYMBOL(vsprintf); ...@@ -1409,14 +1423,15 @@ EXPORT_SYMBOL(vsprintf);
* *
* See the vsnprintf() documentation for format string extensions over C99. * See the vsnprintf() documentation for format string extensions over C99.
*/ */
int sprintf(char * buf, const char *fmt, ...) int sprintf(char *buf, const char *fmt, ...)
{ {
va_list args; va_list args;
int i; int i;
va_start(args, fmt); va_start(args, fmt);
i=vsnprintf(buf, INT_MAX, fmt, args); i = vsnprintf(buf, INT_MAX, fmt, args);
va_end(args); va_end(args);
return i; return i;
} }
EXPORT_SYMBOL(sprintf); EXPORT_SYMBOL(sprintf);
...@@ -1474,7 +1489,6 @@ do { \ ...@@ -1474,7 +1489,6 @@ do { \
str += sizeof(type); \ str += sizeof(type); \
} while (0) } while (0)
while (*fmt) { while (*fmt) {
read = format_decode(fmt, &spec); read = format_decode(fmt, &spec);
...@@ -1562,8 +1576,8 @@ do { \ ...@@ -1562,8 +1576,8 @@ do { \
} }
} }
} }
return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
#undef save_arg #undef save_arg
} }
EXPORT_SYMBOL_GPL(vbin_printf); EXPORT_SYMBOL_GPL(vbin_printf);
...@@ -1595,7 +1609,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1595,7 +1609,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
unsigned long long num; unsigned long long num;
char *str, *end, c; char *str, *end, c;
const char *args = (const char *)bin_buf; const char *args = (const char *)bin_buf;
struct printf_spec spec = {0}; struct printf_spec spec = {0};
if (WARN_ON_ONCE((int) size < 0)) if (WARN_ON_ONCE((int) size < 0))
...@@ -1775,6 +1788,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) ...@@ -1775,6 +1788,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
ret = vbin_printf(bin_buf, size, fmt, args); ret = vbin_printf(bin_buf, size, fmt, args);
va_end(args); va_end(args);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(bprintf); EXPORT_SYMBOL_GPL(bprintf);
...@@ -1787,18 +1801,16 @@ EXPORT_SYMBOL_GPL(bprintf); ...@@ -1787,18 +1801,16 @@ EXPORT_SYMBOL_GPL(bprintf);
* @fmt: format of buffer * @fmt: format of buffer
* @args: arguments * @args: arguments
*/ */
int vsscanf(const char * buf, const char * fmt, va_list args) int vsscanf(const char *buf, const char *fmt, va_list args)
{ {
const char *str = buf; const char *str = buf;
char *next; char *next;
char digit; char digit;
int num = 0; int num = 0;
int qualifier; int qualifier, base, field_width;
int base;
int field_width;
int is_sign = 0; int is_sign = 0;
while(*fmt && *str) { while (*fmt && *str) {
/* skip any white space in format */ /* skip any white space in format */
/* white space in format matchs any amount of /* white space in format matchs any amount of
* white space, including none, in the input. * white space, including none, in the input.
...@@ -1820,7 +1832,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1820,7 +1832,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
if (!*fmt) if (!*fmt)
break; break;
++fmt; ++fmt;
/* skip this conversion. /* skip this conversion.
* advance both strings to next white space * advance both strings to next white space
*/ */
...@@ -1858,10 +1870,10 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1858,10 +1870,10 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
if (!*fmt || !*str) if (!*fmt || !*str)
break; break;
switch(*fmt++) { switch (*fmt++) {
case 'c': case 'c':
{ {
char *s = (char *) va_arg(args,char*); char *s = (char *)va_arg(args, char*);
if (field_width == -1) if (field_width == -1)
field_width = 1; field_width = 1;
do { do {
...@@ -1872,17 +1884,16 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1872,17 +1884,16 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
continue; continue;
case 's': case 's':
{ {
char *s = (char *) va_arg(args, char *); char *s = (char *)va_arg(args, char *);
if(field_width == -1) if (field_width == -1)
field_width = INT_MAX; field_width = INT_MAX;
/* first, skip leading white space in buffer */ /* first, skip leading white space in buffer */
while (isspace(*str)) while (isspace(*str))
str++; str++;
/* now copy until next white space */ /* now copy until next white space */
while (*str && !isspace(*str) && field_width--) { while (*str && !isspace(*str) && field_width--)
*s++ = *str++; *s++ = *str++;
}
*s = '\0'; *s = '\0';
num++; num++;
} }
...@@ -1890,7 +1901,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1890,7 +1901,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
case 'n': case 'n':
/* return number of characters read so far */ /* return number of characters read so far */
{ {
int *i = (int *)va_arg(args,int*); int *i = (int *)va_arg(args, int*);
*i = str - buf; *i = str - buf;
} }
continue; continue;
...@@ -1902,14 +1913,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1902,14 +1913,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
base = 16; base = 16;
break; break;
case 'i': case 'i':
base = 0; base = 0;
case 'd': case 'd':
is_sign = 1; is_sign = 1;
case 'u': case 'u':
break; break;
case '%': case '%':
/* looking for '%' in str */ /* looking for '%' in str */
if (*str++ != '%') if (*str++ != '%')
return num; return num;
continue; continue;
default: default:
...@@ -1928,63 +1939,63 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1928,63 +1939,63 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
digit = *(str + 1); digit = *(str + 1);
if (!digit if (!digit
|| (base == 16 && !isxdigit(digit)) || (base == 16 && !isxdigit(digit))
|| (base == 10 && !isdigit(digit)) || (base == 10 && !isdigit(digit))
|| (base == 8 && (!isdigit(digit) || digit > '7')) || (base == 8 && (!isdigit(digit) || digit > '7'))
|| (base == 0 && !isdigit(digit))) || (base == 0 && !isdigit(digit)))
break; break;
switch(qualifier) { switch (qualifier) {
case 'H': /* that's 'hh' in format */ case 'H': /* that's 'hh' in format */
if (is_sign) { if (is_sign) {
signed char *s = (signed char *) va_arg(args,signed char *); signed char *s = (signed char *)va_arg(args, signed char *);
*s = (signed char) simple_strtol(str,&next,base); *s = (signed char)simple_strtol(str, &next, base);
} else { } else {
unsigned char *s = (unsigned char *) va_arg(args, unsigned char *); unsigned char *s = (unsigned char *)va_arg(args, unsigned char *);
*s = (unsigned char) simple_strtoul(str, &next, base); *s = (unsigned char)simple_strtoul(str, &next, base);
} }
break; break;
case 'h': case 'h':
if (is_sign) { if (is_sign) {
short *s = (short *) va_arg(args,short *); short *s = (short *)va_arg(args, short *);
*s = (short) simple_strtol(str,&next,base); *s = (short)simple_strtol(str, &next, base);
} else { } else {
unsigned short *s = (unsigned short *) va_arg(args, unsigned short *); unsigned short *s = (unsigned short *)va_arg(args, unsigned short *);
*s = (unsigned short) simple_strtoul(str, &next, base); *s = (unsigned short)simple_strtoul(str, &next, base);
} }
break; break;
case 'l': case 'l':
if (is_sign) { if (is_sign) {
long *l = (long *) va_arg(args,long *); long *l = (long *)va_arg(args, long *);
*l = simple_strtol(str,&next,base); *l = simple_strtol(str, &next, base);
} else { } else {
unsigned long *l = (unsigned long*) va_arg(args,unsigned long*); unsigned long *l = (unsigned long *)va_arg(args, unsigned long *);
*l = simple_strtoul(str,&next,base); *l = simple_strtoul(str, &next, base);
} }
break; break;
case 'L': case 'L':
if (is_sign) { if (is_sign) {
long long *l = (long long*) va_arg(args,long long *); long long *l = (long long *)va_arg(args, long long *);
*l = simple_strtoll(str,&next,base); *l = simple_strtoll(str, &next, base);
} else { } else {
unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*); unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *);
*l = simple_strtoull(str,&next,base); *l = simple_strtoull(str, &next, base);
} }
break; break;
case 'Z': case 'Z':
case 'z': case 'z':
{ {
size_t *s = (size_t*) va_arg(args,size_t*); size_t *s = (size_t *)va_arg(args, size_t *);
*s = (size_t) simple_strtoul(str,&next,base); *s = (size_t)simple_strtoul(str, &next, base);
} }
break; break;
default: default:
if (is_sign) { if (is_sign) {
int *i = (int *) va_arg(args, int*); int *i = (int *)va_arg(args, int *);
*i = (int) simple_strtol(str,&next,base); *i = (int)simple_strtol(str, &next, base);
} else { } else {
unsigned int *i = (unsigned int*) va_arg(args, unsigned int*); unsigned int *i = (unsigned int *)va_arg(args, unsigned int*);
*i = (unsigned int) simple_strtoul(str,&next,base); *i = (unsigned int)simple_strtoul(str, &next, base);
} }
break; break;
} }
...@@ -2015,14 +2026,15 @@ EXPORT_SYMBOL(vsscanf); ...@@ -2015,14 +2026,15 @@ EXPORT_SYMBOL(vsscanf);
* @fmt: formatting of buffer * @fmt: formatting of buffer
* @...: resulting arguments * @...: resulting arguments
*/ */
int sscanf(const char * buf, const char * fmt, ...) int sscanf(const char *buf, const char *fmt, ...)
{ {
va_list args; va_list args;
int i; int i;
va_start(args,fmt); va_start(args, fmt);
i = vsscanf(buf,fmt,args); i = vsscanf(buf, fmt, args);
va_end(args); va_end(args);
return i; return i;
} }
EXPORT_SYMBOL(sscanf); EXPORT_SYMBOL(sscanf);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment