diff options
author | André Goddard Rosa <andre.goddard@gmail.com> | 2009-12-14 21:00:57 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-15 11:53:29 -0500 |
commit | 7b9186f5eb0b1705abf7b2fbf33076a6b83f9d89 (patch) | |
tree | 790d988d0d745ef09f760766e94f8f9a84670aa8 /lib | |
parent | 6c356634111c5a7a48264d7c9ec28559e4be11a2 (diff) |
vsprintf: give it some care to please checkpatch.pl
Most relevant complaints were addressed.
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 184 |
1 files changed, 98 insertions, 86 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 99747a58ec72..2e1dda2b549d 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) | 9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> | 13 | * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> |
14 | * - changed to provide snprintf and vsnprintf functions | 14 | * - changed to provide snprintf and vsnprintf functions |
15 | * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de> | 15 | * 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 | result = result * base + value; | 71 | result = result * base + value; |
72 | cp++; | 72 | cp++; |
73 | } | 73 | } |
74 | |||
75 | if (endp) | 74 | if (endp) |
76 | *endp = (char *)cp; | 75 | *endp = (char *)cp; |
76 | |||
77 | return result; | 77 | return result; |
78 | } | 78 | } |
79 | EXPORT_SYMBOL(simple_strtoul); | 79 | EXPORT_SYMBOL(simple_strtoul); |
@@ -86,8 +86,9 @@ EXPORT_SYMBOL(simple_strtoul); | |||
86 | */ | 86 | */ |
87 | long simple_strtol(const char *cp, char **endp, unsigned int base) | 87 | long simple_strtol(const char *cp, char **endp, unsigned int base) |
88 | { | 88 | { |
89 | if(*cp == '-') | 89 | if (*cp == '-') |
90 | return -simple_strtoul(cp + 1, endp, base); | 90 | return -simple_strtoul(cp + 1, endp, base); |
91 | |||
91 | return simple_strtoul(cp, endp, base); | 92 | return simple_strtoul(cp, endp, base); |
92 | } | 93 | } |
93 | EXPORT_SYMBOL(simple_strtol); | 94 | EXPORT_SYMBOL(simple_strtol); |
@@ -117,9 +118,9 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas | |||
117 | result = result * base + value; | 118 | result = result * base + value; |
118 | cp++; | 119 | cp++; |
119 | } | 120 | } |
120 | |||
121 | if (endp) | 121 | if (endp) |
122 | *endp = (char *)cp; | 122 | *endp = (char *)cp; |
123 | |||
123 | return result; | 124 | return result; |
124 | } | 125 | } |
125 | EXPORT_SYMBOL(simple_strtoull); | 126 | EXPORT_SYMBOL(simple_strtoull); |
@@ -132,8 +133,9 @@ EXPORT_SYMBOL(simple_strtoull); | |||
132 | */ | 133 | */ |
133 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) | 134 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) |
134 | { | 135 | { |
135 | if(*cp=='-') | 136 | if (*cp == '-') |
136 | return -simple_strtoull(cp + 1, endp, base); | 137 | return -simple_strtoull(cp + 1, endp, base); |
138 | |||
137 | return simple_strtoull(cp, endp, base); | 139 | return simple_strtoull(cp, endp, base); |
138 | } | 140 | } |
139 | 141 | ||
@@ -173,6 +175,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) | |||
173 | val = simple_strtoul(cp, &tail, base); | 175 | val = simple_strtoul(cp, &tail, base); |
174 | if (tail == cp) | 176 | if (tail == cp) |
175 | return -EINVAL; | 177 | return -EINVAL; |
178 | |||
176 | if ((*tail == '\0') || | 179 | if ((*tail == '\0') || |
177 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | 180 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { |
178 | *res = val; | 181 | *res = val; |
@@ -285,10 +288,11 @@ EXPORT_SYMBOL(strict_strtoll); | |||
285 | 288 | ||
286 | static int skip_atoi(const char **s) | 289 | static int skip_atoi(const char **s) |
287 | { | 290 | { |
288 | int i=0; | 291 | int i = 0; |
289 | 292 | ||
290 | while (isdigit(**s)) | 293 | while (isdigit(**s)) |
291 | i = i*10 + *((*s)++) - '0'; | 294 | i = i*10 + *((*s)++) - '0'; |
295 | |||
292 | return i; | 296 | return i; |
293 | } | 297 | } |
294 | 298 | ||
@@ -302,7 +306,7 @@ static int skip_atoi(const char **s) | |||
302 | /* Formats correctly any integer in [0,99999]. | 306 | /* Formats correctly any integer in [0,99999]. |
303 | * Outputs from one to five digits depending on input. | 307 | * Outputs from one to five digits depending on input. |
304 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 308 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
305 | static char* put_dec_trunc(char *buf, unsigned q) | 309 | static char *put_dec_trunc(char *buf, unsigned q) |
306 | { | 310 | { |
307 | unsigned d3, d2, d1, d0; | 311 | unsigned d3, d2, d1, d0; |
308 | d1 = (q>>4) & 0xf; | 312 | d1 = (q>>4) & 0xf; |
@@ -331,14 +335,15 @@ static char* put_dec_trunc(char *buf, unsigned q) | |||
331 | d3 = d3 - 10*q; | 335 | d3 = d3 - 10*q; |
332 | *buf++ = d3 + '0'; /* next digit */ | 336 | *buf++ = d3 + '0'; /* next digit */ |
333 | if (q != 0) | 337 | if (q != 0) |
334 | *buf++ = q + '0'; /* most sign. digit */ | 338 | *buf++ = q + '0'; /* most sign. digit */ |
335 | } | 339 | } |
336 | } | 340 | } |
337 | } | 341 | } |
342 | |||
338 | return buf; | 343 | return buf; |
339 | } | 344 | } |
340 | /* Same with if's removed. Always emits five digits */ | 345 | /* Same with if's removed. Always emits five digits */ |
341 | static char* put_dec_full(char *buf, unsigned q) | 346 | static char *put_dec_full(char *buf, unsigned q) |
342 | { | 347 | { |
343 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 348 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
344 | /* but anyway, gcc produces better code with full-sized ints */ | 349 | /* but anyway, gcc produces better code with full-sized ints */ |
@@ -347,14 +352,15 @@ static char* put_dec_full(char *buf, unsigned q) | |||
347 | d2 = (q>>8) & 0xf; | 352 | d2 = (q>>8) & 0xf; |
348 | d3 = (q>>12); | 353 | d3 = (q>>12); |
349 | 354 | ||
350 | /* Possible ways to approx. divide by 10 */ | 355 | /* |
351 | /* gcc -O2 replaces multiply with shifts and adds */ | 356 | * Possible ways to approx. divide by 10 |
352 | // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) | 357 | * gcc -O2 replaces multiply with shifts and adds |
353 | // (x * 0x67) >> 10: 1100111 | 358 | * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) |
354 | // (x * 0x34) >> 9: 110100 - same | 359 | * (x * 0x67) >> 10: 1100111 |
355 | // (x * 0x1a) >> 8: 11010 - same | 360 | * (x * 0x34) >> 9: 110100 - same |
356 | // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | 361 | * (x * 0x1a) >> 8: 11010 - same |
357 | 362 | * (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | |
363 | */ | ||
358 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); | 364 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); |
359 | q = (d0 * 0xcd) >> 11; | 365 | q = (d0 * 0xcd) >> 11; |
360 | d0 = d0 - 10*q; | 366 | d0 = d0 - 10*q; |
@@ -375,10 +381,11 @@ static char* put_dec_full(char *buf, unsigned q) | |||
375 | d3 = d3 - 10*q; | 381 | d3 = d3 - 10*q; |
376 | *buf++ = d3 + '0'; | 382 | *buf++ = d3 + '0'; |
377 | *buf++ = q + '0'; | 383 | *buf++ = q + '0'; |
384 | |||
378 | return buf; | 385 | return buf; |
379 | } | 386 | } |
380 | /* No inlining helps gcc to use registers better */ | 387 | /* No inlining helps gcc to use registers better */ |
381 | static noinline char* put_dec(char *buf, unsigned long long num) | 388 | static noinline char *put_dec(char *buf, unsigned long long num) |
382 | { | 389 | { |
383 | while (1) { | 390 | while (1) { |
384 | unsigned rem; | 391 | unsigned rem; |
@@ -448,9 +455,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
448 | spec.flags &= ~ZEROPAD; | 455 | spec.flags &= ~ZEROPAD; |
449 | sign = 0; | 456 | sign = 0; |
450 | if (spec.flags & SIGN) { | 457 | if (spec.flags & SIGN) { |
451 | if ((signed long long) num < 0) { | 458 | if ((signed long long)num < 0) { |
452 | sign = '-'; | 459 | sign = '-'; |
453 | num = - (signed long long) num; | 460 | num = -(signed long long)num; |
454 | spec.field_width--; | 461 | spec.field_width--; |
455 | } else if (spec.flags & PLUS) { | 462 | } else if (spec.flags & PLUS) { |
456 | sign = '+'; | 463 | sign = '+'; |
@@ -478,7 +485,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
478 | else if (spec.base != 10) { /* 8 or 16 */ | 485 | else if (spec.base != 10) { /* 8 or 16 */ |
479 | int mask = spec.base - 1; | 486 | int mask = spec.base - 1; |
480 | int shift = 3; | 487 | int shift = 3; |
481 | if (spec.base == 16) shift = 4; | 488 | |
489 | if (spec.base == 16) | ||
490 | shift = 4; | ||
482 | do { | 491 | do { |
483 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); | 492 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); |
484 | num >>= shift; | 493 | num >>= shift; |
@@ -493,7 +502,7 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
493 | /* leading space padding */ | 502 | /* leading space padding */ |
494 | spec.field_width -= spec.precision; | 503 | spec.field_width -= spec.precision; |
495 | if (!(spec.flags & (ZEROPAD+LEFT))) { | 504 | if (!(spec.flags & (ZEROPAD+LEFT))) { |
496 | while(--spec.field_width >= 0) { | 505 | while (--spec.field_width >= 0) { |
497 | if (buf < end) | 506 | if (buf < end) |
498 | *buf = ' '; | 507 | *buf = ' '; |
499 | ++buf; | 508 | ++buf; |
@@ -543,6 +552,7 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
543 | *buf = ' '; | 552 | *buf = ' '; |
544 | ++buf; | 553 | ++buf; |
545 | } | 554 | } |
555 | |||
546 | return buf; | 556 | return buf; |
547 | } | 557 | } |
548 | 558 | ||
@@ -572,6 +582,7 @@ static char *string(char *buf, char *end, const char *s, struct printf_spec spec | |||
572 | *buf = ' '; | 582 | *buf = ' '; |
573 | ++buf; | 583 | ++buf; |
574 | } | 584 | } |
585 | |||
575 | return buf; | 586 | return buf; |
576 | } | 587 | } |
577 | 588 | ||
@@ -585,11 +596,13 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
585 | sprint_symbol(sym, value); | 596 | sprint_symbol(sym, value); |
586 | else | 597 | else |
587 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | 598 | kallsyms_lookup(value, NULL, NULL, NULL, sym); |
599 | |||
588 | return string(buf, end, sym, spec); | 600 | return string(buf, end, sym, spec); |
589 | #else | 601 | #else |
590 | spec.field_width = 2*sizeof(void *); | 602 | spec.field_width = 2 * sizeof(void *); |
591 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | 603 | spec.flags |= SPECIAL | SMALL | ZEROPAD; |
592 | spec.base = 16; | 604 | spec.base = 16; |
605 | |||
593 | return number(buf, end, value, spec); | 606 | return number(buf, end, value, spec); |
594 | #endif | 607 | #endif |
595 | } | 608 | } |
@@ -718,22 +731,19 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
718 | if (i < 3) | 731 | if (i < 3) |
719 | *p++ = '.'; | 732 | *p++ = '.'; |
720 | } | 733 | } |
721 | |||
722 | *p = '\0'; | 734 | *p = '\0'; |
735 | |||
723 | return p; | 736 | return p; |
724 | } | 737 | } |
725 | 738 | ||
726 | static char *ip6_compressed_string(char *p, const char *addr) | 739 | static char *ip6_compressed_string(char *p, const char *addr) |
727 | { | 740 | { |
728 | int i; | 741 | int i, j, range; |
729 | int j; | ||
730 | int range; | ||
731 | unsigned char zerolength[8]; | 742 | unsigned char zerolength[8]; |
732 | int longest = 1; | 743 | int longest = 1; |
733 | int colonpos = -1; | 744 | int colonpos = -1; |
734 | u16 word; | 745 | u16 word; |
735 | u8 hi; | 746 | u8 hi, lo; |
736 | u8 lo; | ||
737 | bool needcolon = false; | 747 | bool needcolon = false; |
738 | bool useIPv4; | 748 | bool useIPv4; |
739 | struct in6_addr in6; | 749 | struct in6_addr in6; |
@@ -800,22 +810,23 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
800 | *p++ = ':'; | 810 | *p++ = ':'; |
801 | p = ip4_string(p, &in6.s6_addr[12], false); | 811 | p = ip4_string(p, &in6.s6_addr[12], false); |
802 | } | 812 | } |
803 | |||
804 | *p = '\0'; | 813 | *p = '\0'; |
814 | |||
805 | return p; | 815 | return p; |
806 | } | 816 | } |
807 | 817 | ||
808 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 818 | static char *ip6_string(char *p, const char *addr, const char *fmt) |
809 | { | 819 | { |
810 | int i; | 820 | int i; |
821 | |||
811 | for (i = 0; i < 8; i++) { | 822 | for (i = 0; i < 8; i++) { |
812 | p = pack_hex_byte(p, *addr++); | 823 | p = pack_hex_byte(p, *addr++); |
813 | p = pack_hex_byte(p, *addr++); | 824 | p = pack_hex_byte(p, *addr++); |
814 | if (fmt[0] == 'I' && i != 7) | 825 | if (fmt[0] == 'I' && i != 7) |
815 | *p++ = ':'; | 826 | *p++ = ':'; |
816 | } | 827 | } |
817 | |||
818 | *p = '\0'; | 828 | *p = '\0'; |
829 | |||
819 | return p; | 830 | return p; |
820 | } | 831 | } |
821 | 832 | ||
@@ -1322,7 +1333,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1322 | { | 1333 | { |
1323 | int i; | 1334 | int i; |
1324 | 1335 | ||
1325 | i=vsnprintf(buf,size,fmt,args); | 1336 | i = vsnprintf(buf, size, fmt, args); |
1337 | |||
1326 | return (i >= size) ? (size - 1) : i; | 1338 | return (i >= size) ? (size - 1) : i; |
1327 | } | 1339 | } |
1328 | EXPORT_SYMBOL(vscnprintf); | 1340 | EXPORT_SYMBOL(vscnprintf); |
@@ -1341,14 +1353,15 @@ EXPORT_SYMBOL(vscnprintf); | |||
1341 | * | 1353 | * |
1342 | * See the vsnprintf() documentation for format string extensions over C99. | 1354 | * See the vsnprintf() documentation for format string extensions over C99. |
1343 | */ | 1355 | */ |
1344 | int snprintf(char * buf, size_t size, const char *fmt, ...) | 1356 | int snprintf(char *buf, size_t size, const char *fmt, ...) |
1345 | { | 1357 | { |
1346 | va_list args; | 1358 | va_list args; |
1347 | int i; | 1359 | int i; |
1348 | 1360 | ||
1349 | va_start(args, fmt); | 1361 | va_start(args, fmt); |
1350 | i=vsnprintf(buf,size,fmt,args); | 1362 | i = vsnprintf(buf, size, fmt, args); |
1351 | va_end(args); | 1363 | va_end(args); |
1364 | |||
1352 | return i; | 1365 | return i; |
1353 | } | 1366 | } |
1354 | EXPORT_SYMBOL(snprintf); | 1367 | EXPORT_SYMBOL(snprintf); |
@@ -1364,7 +1377,7 @@ EXPORT_SYMBOL(snprintf); | |||
1364 | * the trailing '\0'. If @size is <= 0 the function returns 0. | 1377 | * the trailing '\0'. If @size is <= 0 the function returns 0. |
1365 | */ | 1378 | */ |
1366 | 1379 | ||
1367 | int scnprintf(char * buf, size_t size, const char *fmt, ...) | 1380 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
1368 | { | 1381 | { |
1369 | va_list args; | 1382 | va_list args; |
1370 | int i; | 1383 | int i; |
@@ -1372,6 +1385,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) | |||
1372 | va_start(args, fmt); | 1385 | va_start(args, fmt); |
1373 | i = vsnprintf(buf, size, fmt, args); | 1386 | i = vsnprintf(buf, size, fmt, args); |
1374 | va_end(args); | 1387 | va_end(args); |
1388 | |||
1375 | return (i >= size) ? (size - 1) : i; | 1389 | return (i >= size) ? (size - 1) : i; |
1376 | } | 1390 | } |
1377 | EXPORT_SYMBOL(scnprintf); | 1391 | EXPORT_SYMBOL(scnprintf); |
@@ -1409,14 +1423,15 @@ EXPORT_SYMBOL(vsprintf); | |||
1409 | * | 1423 | * |
1410 | * See the vsnprintf() documentation for format string extensions over C99. | 1424 | * See the vsnprintf() documentation for format string extensions over C99. |
1411 | */ | 1425 | */ |
1412 | int sprintf(char * buf, const char *fmt, ...) | 1426 | int sprintf(char *buf, const char *fmt, ...) |
1413 | { | 1427 | { |
1414 | va_list args; | 1428 | va_list args; |
1415 | int i; | 1429 | int i; |
1416 | 1430 | ||
1417 | va_start(args, fmt); | 1431 | va_start(args, fmt); |
1418 | i=vsnprintf(buf, INT_MAX, fmt, args); | 1432 | i = vsnprintf(buf, INT_MAX, fmt, args); |
1419 | va_end(args); | 1433 | va_end(args); |
1434 | |||
1420 | return i; | 1435 | return i; |
1421 | } | 1436 | } |
1422 | EXPORT_SYMBOL(sprintf); | 1437 | EXPORT_SYMBOL(sprintf); |
@@ -1474,7 +1489,6 @@ do { \ | |||
1474 | str += sizeof(type); \ | 1489 | str += sizeof(type); \ |
1475 | } while (0) | 1490 | } while (0) |
1476 | 1491 | ||
1477 | |||
1478 | while (*fmt) { | 1492 | while (*fmt) { |
1479 | read = format_decode(fmt, &spec); | 1493 | read = format_decode(fmt, &spec); |
1480 | 1494 | ||
@@ -1562,8 +1576,8 @@ do { \ | |||
1562 | } | 1576 | } |
1563 | } | 1577 | } |
1564 | } | 1578 | } |
1565 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1566 | 1579 | ||
1580 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1567 | #undef save_arg | 1581 | #undef save_arg |
1568 | } | 1582 | } |
1569 | EXPORT_SYMBOL_GPL(vbin_printf); | 1583 | 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 | unsigned long long num; | 1609 | unsigned long long num; |
1596 | char *str, *end, c; | 1610 | char *str, *end, c; |
1597 | const char *args = (const char *)bin_buf; | 1611 | const char *args = (const char *)bin_buf; |
1598 | |||
1599 | struct printf_spec spec = {0}; | 1612 | struct printf_spec spec = {0}; |
1600 | 1613 | ||
1601 | if (WARN_ON_ONCE((int) size < 0)) | 1614 | if (WARN_ON_ONCE((int) size < 0)) |
@@ -1775,6 +1788,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) | |||
1775 | va_start(args, fmt); | 1788 | va_start(args, fmt); |
1776 | ret = vbin_printf(bin_buf, size, fmt, args); | 1789 | ret = vbin_printf(bin_buf, size, fmt, args); |
1777 | va_end(args); | 1790 | va_end(args); |
1791 | |||
1778 | return ret; | 1792 | return ret; |
1779 | } | 1793 | } |
1780 | EXPORT_SYMBOL_GPL(bprintf); | 1794 | EXPORT_SYMBOL_GPL(bprintf); |
@@ -1787,18 +1801,16 @@ EXPORT_SYMBOL_GPL(bprintf); | |||
1787 | * @fmt: format of buffer | 1801 | * @fmt: format of buffer |
1788 | * @args: arguments | 1802 | * @args: arguments |
1789 | */ | 1803 | */ |
1790 | int vsscanf(const char * buf, const char * fmt, va_list args) | 1804 | int vsscanf(const char *buf, const char *fmt, va_list args) |
1791 | { | 1805 | { |
1792 | const char *str = buf; | 1806 | const char *str = buf; |
1793 | char *next; | 1807 | char *next; |
1794 | char digit; | 1808 | char digit; |
1795 | int num = 0; | 1809 | int num = 0; |
1796 | int qualifier; | 1810 | int qualifier, base, field_width; |
1797 | int base; | ||
1798 | int field_width; | ||
1799 | int is_sign = 0; | 1811 | int is_sign = 0; |
1800 | 1812 | ||
1801 | while(*fmt && *str) { | 1813 | while (*fmt && *str) { |
1802 | /* skip any white space in format */ | 1814 | /* skip any white space in format */ |
1803 | /* white space in format matchs any amount of | 1815 | /* white space in format matchs any amount of |
1804 | * white space, including none, in the input. | 1816 | * white space, including none, in the input. |
@@ -1820,7 +1832,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1820 | if (!*fmt) | 1832 | if (!*fmt) |
1821 | break; | 1833 | break; |
1822 | ++fmt; | 1834 | ++fmt; |
1823 | 1835 | ||
1824 | /* skip this conversion. | 1836 | /* skip this conversion. |
1825 | * advance both strings to next white space | 1837 | * advance both strings to next white space |
1826 | */ | 1838 | */ |
@@ -1858,10 +1870,10 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1858 | if (!*fmt || !*str) | 1870 | if (!*fmt || !*str) |
1859 | break; | 1871 | break; |
1860 | 1872 | ||
1861 | switch(*fmt++) { | 1873 | switch (*fmt++) { |
1862 | case 'c': | 1874 | case 'c': |
1863 | { | 1875 | { |
1864 | char *s = (char *) va_arg(args,char*); | 1876 | char *s = (char *)va_arg(args, char*); |
1865 | if (field_width == -1) | 1877 | if (field_width == -1) |
1866 | field_width = 1; | 1878 | field_width = 1; |
1867 | do { | 1879 | do { |
@@ -1872,17 +1884,16 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1872 | continue; | 1884 | continue; |
1873 | case 's': | 1885 | case 's': |
1874 | { | 1886 | { |
1875 | char *s = (char *) va_arg(args, char *); | 1887 | char *s = (char *)va_arg(args, char *); |
1876 | if(field_width == -1) | 1888 | if (field_width == -1) |
1877 | field_width = INT_MAX; | 1889 | field_width = INT_MAX; |
1878 | /* first, skip leading white space in buffer */ | 1890 | /* first, skip leading white space in buffer */ |
1879 | while (isspace(*str)) | 1891 | while (isspace(*str)) |
1880 | str++; | 1892 | str++; |
1881 | 1893 | ||
1882 | /* now copy until next white space */ | 1894 | /* now copy until next white space */ |
1883 | while (*str && !isspace(*str) && field_width--) { | 1895 | while (*str && !isspace(*str) && field_width--) |
1884 | *s++ = *str++; | 1896 | *s++ = *str++; |
1885 | } | ||
1886 | *s = '\0'; | 1897 | *s = '\0'; |
1887 | num++; | 1898 | num++; |
1888 | } | 1899 | } |
@@ -1890,7 +1901,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1890 | case 'n': | 1901 | case 'n': |
1891 | /* return number of characters read so far */ | 1902 | /* return number of characters read so far */ |
1892 | { | 1903 | { |
1893 | int *i = (int *)va_arg(args,int*); | 1904 | int *i = (int *)va_arg(args, int*); |
1894 | *i = str - buf; | 1905 | *i = str - buf; |
1895 | } | 1906 | } |
1896 | continue; | 1907 | continue; |
@@ -1902,14 +1913,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1902 | base = 16; | 1913 | base = 16; |
1903 | break; | 1914 | break; |
1904 | case 'i': | 1915 | case 'i': |
1905 | base = 0; | 1916 | base = 0; |
1906 | case 'd': | 1917 | case 'd': |
1907 | is_sign = 1; | 1918 | is_sign = 1; |
1908 | case 'u': | 1919 | case 'u': |
1909 | break; | 1920 | break; |
1910 | case '%': | 1921 | case '%': |
1911 | /* looking for '%' in str */ | 1922 | /* looking for '%' in str */ |
1912 | if (*str++ != '%') | 1923 | if (*str++ != '%') |
1913 | return num; | 1924 | return num; |
1914 | continue; | 1925 | continue; |
1915 | default: | 1926 | default: |
@@ -1928,63 +1939,63 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1928 | digit = *(str + 1); | 1939 | digit = *(str + 1); |
1929 | 1940 | ||
1930 | if (!digit | 1941 | if (!digit |
1931 | || (base == 16 && !isxdigit(digit)) | 1942 | || (base == 16 && !isxdigit(digit)) |
1932 | || (base == 10 && !isdigit(digit)) | 1943 | || (base == 10 && !isdigit(digit)) |
1933 | || (base == 8 && (!isdigit(digit) || digit > '7')) | 1944 | || (base == 8 && (!isdigit(digit) || digit > '7')) |
1934 | || (base == 0 && !isdigit(digit))) | 1945 | || (base == 0 && !isdigit(digit))) |
1935 | break; | 1946 | break; |
1936 | 1947 | ||
1937 | switch(qualifier) { | 1948 | switch (qualifier) { |
1938 | case 'H': /* that's 'hh' in format */ | 1949 | case 'H': /* that's 'hh' in format */ |
1939 | if (is_sign) { | 1950 | if (is_sign) { |
1940 | signed char *s = (signed char *) va_arg(args,signed char *); | 1951 | signed char *s = (signed char *)va_arg(args, signed char *); |
1941 | *s = (signed char) simple_strtol(str,&next,base); | 1952 | *s = (signed char)simple_strtol(str, &next, base); |
1942 | } else { | 1953 | } else { |
1943 | unsigned char *s = (unsigned char *) va_arg(args, unsigned char *); | 1954 | unsigned char *s = (unsigned char *)va_arg(args, unsigned char *); |
1944 | *s = (unsigned char) simple_strtoul(str, &next, base); | 1955 | *s = (unsigned char)simple_strtoul(str, &next, base); |
1945 | } | 1956 | } |
1946 | break; | 1957 | break; |
1947 | case 'h': | 1958 | case 'h': |
1948 | if (is_sign) { | 1959 | if (is_sign) { |
1949 | short *s = (short *) va_arg(args,short *); | 1960 | short *s = (short *)va_arg(args, short *); |
1950 | *s = (short) simple_strtol(str,&next,base); | 1961 | *s = (short)simple_strtol(str, &next, base); |
1951 | } else { | 1962 | } else { |
1952 | unsigned short *s = (unsigned short *) va_arg(args, unsigned short *); | 1963 | unsigned short *s = (unsigned short *)va_arg(args, unsigned short *); |
1953 | *s = (unsigned short) simple_strtoul(str, &next, base); | 1964 | *s = (unsigned short)simple_strtoul(str, &next, base); |
1954 | } | 1965 | } |
1955 | break; | 1966 | break; |
1956 | case 'l': | 1967 | case 'l': |
1957 | if (is_sign) { | 1968 | if (is_sign) { |
1958 | long *l = (long *) va_arg(args,long *); | 1969 | long *l = (long *)va_arg(args, long *); |
1959 | *l = simple_strtol(str,&next,base); | 1970 | *l = simple_strtol(str, &next, base); |
1960 | } else { | 1971 | } else { |
1961 | unsigned long *l = (unsigned long*) va_arg(args,unsigned long*); | 1972 | unsigned long *l = (unsigned long *)va_arg(args, unsigned long *); |
1962 | *l = simple_strtoul(str,&next,base); | 1973 | *l = simple_strtoul(str, &next, base); |
1963 | } | 1974 | } |
1964 | break; | 1975 | break; |
1965 | case 'L': | 1976 | case 'L': |
1966 | if (is_sign) { | 1977 | if (is_sign) { |
1967 | long long *l = (long long*) va_arg(args,long long *); | 1978 | long long *l = (long long *)va_arg(args, long long *); |
1968 | *l = simple_strtoll(str,&next,base); | 1979 | *l = simple_strtoll(str, &next, base); |
1969 | } else { | 1980 | } else { |
1970 | unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*); | 1981 | unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *); |
1971 | *l = simple_strtoull(str,&next,base); | 1982 | *l = simple_strtoull(str, &next, base); |
1972 | } | 1983 | } |
1973 | break; | 1984 | break; |
1974 | case 'Z': | 1985 | case 'Z': |
1975 | case 'z': | 1986 | case 'z': |
1976 | { | 1987 | { |
1977 | size_t *s = (size_t*) va_arg(args,size_t*); | 1988 | size_t *s = (size_t *)va_arg(args, size_t *); |
1978 | *s = (size_t) simple_strtoul(str,&next,base); | 1989 | *s = (size_t)simple_strtoul(str, &next, base); |
1979 | } | 1990 | } |
1980 | break; | 1991 | break; |
1981 | default: | 1992 | default: |
1982 | if (is_sign) { | 1993 | if (is_sign) { |
1983 | int *i = (int *) va_arg(args, int*); | 1994 | int *i = (int *)va_arg(args, int *); |
1984 | *i = (int) simple_strtol(str,&next,base); | 1995 | *i = (int)simple_strtol(str, &next, base); |
1985 | } else { | 1996 | } else { |
1986 | unsigned int *i = (unsigned int*) va_arg(args, unsigned int*); | 1997 | unsigned int *i = (unsigned int *)va_arg(args, unsigned int*); |
1987 | *i = (unsigned int) simple_strtoul(str,&next,base); | 1998 | *i = (unsigned int)simple_strtoul(str, &next, base); |
1988 | } | 1999 | } |
1989 | break; | 2000 | break; |
1990 | } | 2001 | } |
@@ -2015,14 +2026,15 @@ EXPORT_SYMBOL(vsscanf); | |||
2015 | * @fmt: formatting of buffer | 2026 | * @fmt: formatting of buffer |
2016 | * @...: resulting arguments | 2027 | * @...: resulting arguments |
2017 | */ | 2028 | */ |
2018 | int sscanf(const char * buf, const char * fmt, ...) | 2029 | int sscanf(const char *buf, const char *fmt, ...) |
2019 | { | 2030 | { |
2020 | va_list args; | 2031 | va_list args; |
2021 | int i; | 2032 | int i; |
2022 | 2033 | ||
2023 | va_start(args,fmt); | 2034 | va_start(args, fmt); |
2024 | i = vsscanf(buf,fmt,args); | 2035 | i = vsscanf(buf, fmt, args); |
2025 | va_end(args); | 2036 | va_end(args); |
2037 | |||
2026 | return i; | 2038 | return i; |
2027 | } | 2039 | } |
2028 | EXPORT_SYMBOL(sscanf); | 2040 | EXPORT_SYMBOL(sscanf); |