diff options
Diffstat (limited to 'lib/vsprintf.c')
| -rw-r--r-- | lib/vsprintf.c | 545 |
1 files changed, 343 insertions, 202 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 33bed5e67a21..af4aaa6c36f3 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> |
| @@ -47,14 +47,14 @@ static unsigned int simple_guess_base(const char *cp) | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * simple_strtoul - convert a string to an unsigned long | 50 | * simple_strtoull - convert a string to an unsigned long long |
| 51 | * @cp: The start of the string | 51 | * @cp: The start of the string |
| 52 | * @endp: A pointer to the end of the parsed string will be placed here | 52 | * @endp: A pointer to the end of the parsed string will be placed here |
| 53 | * @base: The number base to use | 53 | * @base: The number base to use |
| 54 | */ | 54 | */ |
| 55 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) | 55 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) |
| 56 | { | 56 | { |
| 57 | unsigned long result = 0; | 57 | unsigned long long result = 0; |
| 58 | 58 | ||
| 59 | if (!base) | 59 | if (!base) |
| 60 | base = simple_guess_base(cp); | 60 | base = simple_guess_base(cp); |
| @@ -71,58 +71,39 @@ 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_strtoull); |
| 80 | 80 | ||
| 81 | /** | 81 | /** |
| 82 | * simple_strtol - convert a string to a signed long | 82 | * simple_strtoul - convert a string to an unsigned long |
| 83 | * @cp: The start of the string | 83 | * @cp: The start of the string |
| 84 | * @endp: A pointer to the end of the parsed string will be placed here | 84 | * @endp: A pointer to the end of the parsed string will be placed here |
| 85 | * @base: The number base to use | 85 | * @base: The number base to use |
| 86 | */ | 86 | */ |
| 87 | long simple_strtol(const char *cp, char **endp, unsigned int base) | 87 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) |
| 88 | { | 88 | { |
| 89 | if(*cp == '-') | 89 | return simple_strtoull(cp, endp, base); |
| 90 | return -simple_strtoul(cp + 1, endp, base); | ||
| 91 | return simple_strtoul(cp, endp, base); | ||
| 92 | } | 90 | } |
| 93 | EXPORT_SYMBOL(simple_strtol); | 91 | EXPORT_SYMBOL(simple_strtoul); |
| 94 | 92 | ||
| 95 | /** | 93 | /** |
| 96 | * simple_strtoull - convert a string to an unsigned long long | 94 | * simple_strtol - convert a string to a signed long |
| 97 | * @cp: The start of the string | 95 | * @cp: The start of the string |
| 98 | * @endp: A pointer to the end of the parsed string will be placed here | 96 | * @endp: A pointer to the end of the parsed string will be placed here |
| 99 | * @base: The number base to use | 97 | * @base: The number base to use |
| 100 | */ | 98 | */ |
| 101 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) | 99 | long simple_strtol(const char *cp, char **endp, unsigned int base) |
| 102 | { | 100 | { |
| 103 | unsigned long long result = 0; | 101 | if (*cp == '-') |
| 104 | 102 | return -simple_strtoul(cp + 1, endp, base); | |
| 105 | if (!base) | ||
| 106 | base = simple_guess_base(cp); | ||
| 107 | |||
| 108 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') | ||
| 109 | cp += 2; | ||
| 110 | |||
| 111 | while (isxdigit(*cp)) { | ||
| 112 | unsigned int value; | ||
| 113 | |||
| 114 | value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; | ||
| 115 | if (value >= base) | ||
| 116 | break; | ||
| 117 | result = result * base + value; | ||
| 118 | cp++; | ||
| 119 | } | ||
| 120 | 103 | ||
| 121 | if (endp) | 104 | return simple_strtoul(cp, endp, base); |
| 122 | *endp = (char *)cp; | ||
| 123 | return result; | ||
| 124 | } | 105 | } |
| 125 | EXPORT_SYMBOL(simple_strtoull); | 106 | EXPORT_SYMBOL(simple_strtol); |
| 126 | 107 | ||
| 127 | /** | 108 | /** |
| 128 | * simple_strtoll - convert a string to a signed long long | 109 | * simple_strtoll - convert a string to a signed long long |
| @@ -132,8 +113,9 @@ EXPORT_SYMBOL(simple_strtoull); | |||
| 132 | */ | 113 | */ |
| 133 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) | 114 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) |
| 134 | { | 115 | { |
| 135 | if(*cp=='-') | 116 | if (*cp == '-') |
| 136 | return -simple_strtoull(cp + 1, endp, base); | 117 | return -simple_strtoull(cp + 1, endp, base); |
| 118 | |||
| 137 | return simple_strtoull(cp, endp, base); | 119 | return simple_strtoull(cp, endp, base); |
| 138 | } | 120 | } |
| 139 | 121 | ||
| @@ -173,6 +155,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) | |||
| 173 | val = simple_strtoul(cp, &tail, base); | 155 | val = simple_strtoul(cp, &tail, base); |
| 174 | if (tail == cp) | 156 | if (tail == cp) |
| 175 | return -EINVAL; | 157 | return -EINVAL; |
| 158 | |||
| 176 | if ((*tail == '\0') || | 159 | if ((*tail == '\0') || |
| 177 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | 160 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { |
| 178 | *res = val; | 161 | *res = val; |
| @@ -285,10 +268,11 @@ EXPORT_SYMBOL(strict_strtoll); | |||
| 285 | 268 | ||
| 286 | static int skip_atoi(const char **s) | 269 | static int skip_atoi(const char **s) |
| 287 | { | 270 | { |
| 288 | int i=0; | 271 | int i = 0; |
| 289 | 272 | ||
| 290 | while (isdigit(**s)) | 273 | while (isdigit(**s)) |
| 291 | i = i*10 + *((*s)++) - '0'; | 274 | i = i*10 + *((*s)++) - '0'; |
| 275 | |||
| 292 | return i; | 276 | return i; |
| 293 | } | 277 | } |
| 294 | 278 | ||
| @@ -302,7 +286,7 @@ static int skip_atoi(const char **s) | |||
| 302 | /* Formats correctly any integer in [0,99999]. | 286 | /* Formats correctly any integer in [0,99999]. |
| 303 | * Outputs from one to five digits depending on input. | 287 | * Outputs from one to five digits depending on input. |
| 304 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 288 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
| 305 | static char* put_dec_trunc(char *buf, unsigned q) | 289 | static char *put_dec_trunc(char *buf, unsigned q) |
| 306 | { | 290 | { |
| 307 | unsigned d3, d2, d1, d0; | 291 | unsigned d3, d2, d1, d0; |
| 308 | d1 = (q>>4) & 0xf; | 292 | d1 = (q>>4) & 0xf; |
| @@ -331,14 +315,15 @@ static char* put_dec_trunc(char *buf, unsigned q) | |||
| 331 | d3 = d3 - 10*q; | 315 | d3 = d3 - 10*q; |
| 332 | *buf++ = d3 + '0'; /* next digit */ | 316 | *buf++ = d3 + '0'; /* next digit */ |
| 333 | if (q != 0) | 317 | if (q != 0) |
| 334 | *buf++ = q + '0'; /* most sign. digit */ | 318 | *buf++ = q + '0'; /* most sign. digit */ |
| 335 | } | 319 | } |
| 336 | } | 320 | } |
| 337 | } | 321 | } |
| 322 | |||
| 338 | return buf; | 323 | return buf; |
| 339 | } | 324 | } |
| 340 | /* Same with if's removed. Always emits five digits */ | 325 | /* Same with if's removed. Always emits five digits */ |
| 341 | static char* put_dec_full(char *buf, unsigned q) | 326 | static char *put_dec_full(char *buf, unsigned q) |
| 342 | { | 327 | { |
| 343 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 328 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
| 344 | /* but anyway, gcc produces better code with full-sized ints */ | 329 | /* but anyway, gcc produces better code with full-sized ints */ |
| @@ -347,14 +332,15 @@ static char* put_dec_full(char *buf, unsigned q) | |||
| 347 | d2 = (q>>8) & 0xf; | 332 | d2 = (q>>8) & 0xf; |
| 348 | d3 = (q>>12); | 333 | d3 = (q>>12); |
| 349 | 334 | ||
| 350 | /* Possible ways to approx. divide by 10 */ | 335 | /* |
| 351 | /* gcc -O2 replaces multiply with shifts and adds */ | 336 | * Possible ways to approx. divide by 10 |
| 352 | // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) | 337 | * gcc -O2 replaces multiply with shifts and adds |
| 353 | // (x * 0x67) >> 10: 1100111 | 338 | * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) |
| 354 | // (x * 0x34) >> 9: 110100 - same | 339 | * (x * 0x67) >> 10: 1100111 |
| 355 | // (x * 0x1a) >> 8: 11010 - same | 340 | * (x * 0x34) >> 9: 110100 - same |
| 356 | // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | 341 | * (x * 0x1a) >> 8: 11010 - same |
| 357 | 342 | * (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | |
| 343 | */ | ||
| 358 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); | 344 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); |
| 359 | q = (d0 * 0xcd) >> 11; | 345 | q = (d0 * 0xcd) >> 11; |
| 360 | d0 = d0 - 10*q; | 346 | d0 = d0 - 10*q; |
| @@ -375,10 +361,11 @@ static char* put_dec_full(char *buf, unsigned q) | |||
| 375 | d3 = d3 - 10*q; | 361 | d3 = d3 - 10*q; |
| 376 | *buf++ = d3 + '0'; | 362 | *buf++ = d3 + '0'; |
| 377 | *buf++ = q + '0'; | 363 | *buf++ = q + '0'; |
| 364 | |||
| 378 | return buf; | 365 | return buf; |
| 379 | } | 366 | } |
| 380 | /* No inlining helps gcc to use registers better */ | 367 | /* No inlining helps gcc to use registers better */ |
| 381 | static noinline char* put_dec(char *buf, unsigned long long num) | 368 | static noinline char *put_dec(char *buf, unsigned long long num) |
| 382 | { | 369 | { |
| 383 | while (1) { | 370 | while (1) { |
| 384 | unsigned rem; | 371 | unsigned rem; |
| @@ -448,9 +435,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
| 448 | spec.flags &= ~ZEROPAD; | 435 | spec.flags &= ~ZEROPAD; |
| 449 | sign = 0; | 436 | sign = 0; |
| 450 | if (spec.flags & SIGN) { | 437 | if (spec.flags & SIGN) { |
| 451 | if ((signed long long) num < 0) { | 438 | if ((signed long long)num < 0) { |
| 452 | sign = '-'; | 439 | sign = '-'; |
| 453 | num = - (signed long long) num; | 440 | num = -(signed long long)num; |
| 454 | spec.field_width--; | 441 | spec.field_width--; |
| 455 | } else if (spec.flags & PLUS) { | 442 | } else if (spec.flags & PLUS) { |
| 456 | sign = '+'; | 443 | sign = '+'; |
| @@ -478,7 +465,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
| 478 | else if (spec.base != 10) { /* 8 or 16 */ | 465 | else if (spec.base != 10) { /* 8 or 16 */ |
| 479 | int mask = spec.base - 1; | 466 | int mask = spec.base - 1; |
| 480 | int shift = 3; | 467 | int shift = 3; |
| 481 | if (spec.base == 16) shift = 4; | 468 | |
| 469 | if (spec.base == 16) | ||
| 470 | shift = 4; | ||
| 482 | do { | 471 | do { |
| 483 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); | 472 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); |
| 484 | num >>= shift; | 473 | num >>= shift; |
| @@ -493,7 +482,7 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
| 493 | /* leading space padding */ | 482 | /* leading space padding */ |
| 494 | spec.field_width -= spec.precision; | 483 | spec.field_width -= spec.precision; |
| 495 | if (!(spec.flags & (ZEROPAD+LEFT))) { | 484 | if (!(spec.flags & (ZEROPAD+LEFT))) { |
| 496 | while(--spec.field_width >= 0) { | 485 | while (--spec.field_width >= 0) { |
| 497 | if (buf < end) | 486 | if (buf < end) |
| 498 | *buf = ' '; | 487 | *buf = ' '; |
| 499 | ++buf; | 488 | ++buf; |
| @@ -543,15 +532,16 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
| 543 | *buf = ' '; | 532 | *buf = ' '; |
| 544 | ++buf; | 533 | ++buf; |
| 545 | } | 534 | } |
| 535 | |||
| 546 | return buf; | 536 | return buf; |
| 547 | } | 537 | } |
| 548 | 538 | ||
| 549 | static char *string(char *buf, char *end, char *s, struct printf_spec spec) | 539 | static char *string(char *buf, char *end, const char *s, struct printf_spec spec) |
| 550 | { | 540 | { |
| 551 | int len, i; | 541 | int len, i; |
| 552 | 542 | ||
| 553 | if ((unsigned long)s < PAGE_SIZE) | 543 | if ((unsigned long)s < PAGE_SIZE) |
| 554 | s = "<NULL>"; | 544 | s = "(null)"; |
| 555 | 545 | ||
| 556 | len = strnlen(s, spec.precision); | 546 | len = strnlen(s, spec.precision); |
| 557 | 547 | ||
| @@ -572,6 +562,7 @@ static char *string(char *buf, char *end, char *s, struct printf_spec spec) | |||
| 572 | *buf = ' '; | 562 | *buf = ' '; |
| 573 | ++buf; | 563 | ++buf; |
| 574 | } | 564 | } |
| 565 | |||
| 575 | return buf; | 566 | return buf; |
| 576 | } | 567 | } |
| 577 | 568 | ||
| @@ -585,47 +576,101 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
| 585 | sprint_symbol(sym, value); | 576 | sprint_symbol(sym, value); |
| 586 | else | 577 | else |
| 587 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | 578 | kallsyms_lookup(value, NULL, NULL, NULL, sym); |
| 579 | |||
| 588 | return string(buf, end, sym, spec); | 580 | return string(buf, end, sym, spec); |
| 589 | #else | 581 | #else |
| 590 | spec.field_width = 2*sizeof(void *); | 582 | spec.field_width = 2 * sizeof(void *); |
| 591 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | 583 | spec.flags |= SPECIAL | SMALL | ZEROPAD; |
| 592 | spec.base = 16; | 584 | spec.base = 16; |
| 585 | |||
| 593 | return number(buf, end, value, spec); | 586 | return number(buf, end, value, spec); |
| 594 | #endif | 587 | #endif |
| 595 | } | 588 | } |
| 596 | 589 | ||
| 597 | static char *resource_string(char *buf, char *end, struct resource *res, | 590 | static char *resource_string(char *buf, char *end, struct resource *res, |
| 598 | struct printf_spec spec) | 591 | struct printf_spec spec, const char *fmt) |
| 599 | { | 592 | { |
| 600 | #ifndef IO_RSRC_PRINTK_SIZE | 593 | #ifndef IO_RSRC_PRINTK_SIZE |
| 601 | #define IO_RSRC_PRINTK_SIZE 4 | 594 | #define IO_RSRC_PRINTK_SIZE 6 |
| 602 | #endif | 595 | #endif |
| 603 | 596 | ||
| 604 | #ifndef MEM_RSRC_PRINTK_SIZE | 597 | #ifndef MEM_RSRC_PRINTK_SIZE |
| 605 | #define MEM_RSRC_PRINTK_SIZE 8 | 598 | #define MEM_RSRC_PRINTK_SIZE 10 |
| 606 | #endif | 599 | #endif |
| 607 | struct printf_spec num_spec = { | 600 | struct printf_spec hex_spec = { |
| 608 | .base = 16, | 601 | .base = 16, |
| 609 | .precision = -1, | 602 | .precision = -1, |
| 610 | .flags = SPECIAL | SMALL | ZEROPAD, | 603 | .flags = SPECIAL | SMALL | ZEROPAD, |
| 611 | }; | 604 | }; |
| 612 | /* room for the actual numbers, the two "0x", -, [, ] and the final zero */ | 605 | struct printf_spec dec_spec = { |
| 613 | char sym[4*sizeof(resource_size_t) + 8]; | 606 | .base = 10, |
| 607 | .precision = -1, | ||
| 608 | .flags = 0, | ||
| 609 | }; | ||
| 610 | struct printf_spec str_spec = { | ||
| 611 | .field_width = -1, | ||
| 612 | .precision = 10, | ||
| 613 | .flags = LEFT, | ||
| 614 | }; | ||
| 615 | struct printf_spec flag_spec = { | ||
| 616 | .base = 16, | ||
| 617 | .precision = -1, | ||
| 618 | .flags = SPECIAL | SMALL, | ||
| 619 | }; | ||
| 620 | |||
| 621 | /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8) | ||
| 622 | * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */ | ||
| 623 | #define RSRC_BUF_SIZE ((2 * sizeof(resource_size_t)) + 4) | ||
| 624 | #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) | ||
| 625 | #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref disabled]") | ||
| 626 | #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") | ||
| 627 | char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, | ||
| 628 | 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; | ||
| 629 | |||
| 614 | char *p = sym, *pend = sym + sizeof(sym); | 630 | char *p = sym, *pend = sym + sizeof(sym); |
| 615 | int size = -1; | 631 | int size = -1, addr = 0; |
| 632 | int decode = (fmt[0] == 'R') ? 1 : 0; | ||
| 616 | 633 | ||
| 617 | if (res->flags & IORESOURCE_IO) | 634 | if (res->flags & IORESOURCE_IO) { |
| 618 | size = IO_RSRC_PRINTK_SIZE; | 635 | size = IO_RSRC_PRINTK_SIZE; |
| 619 | else if (res->flags & IORESOURCE_MEM) | 636 | addr = 1; |
| 637 | } else if (res->flags & IORESOURCE_MEM) { | ||
| 620 | size = MEM_RSRC_PRINTK_SIZE; | 638 | size = MEM_RSRC_PRINTK_SIZE; |
| 639 | addr = 1; | ||
| 640 | } | ||
| 621 | 641 | ||
| 622 | *p++ = '['; | 642 | *p++ = '['; |
| 623 | num_spec.field_width = size; | 643 | if (res->flags & IORESOURCE_IO) |
| 624 | p = number(p, pend, res->start, num_spec); | 644 | p = string(p, pend, "io ", str_spec); |
| 625 | *p++ = '-'; | 645 | else if (res->flags & IORESOURCE_MEM) |
| 626 | p = number(p, pend, res->end, num_spec); | 646 | p = string(p, pend, "mem ", str_spec); |
| 647 | else if (res->flags & IORESOURCE_IRQ) | ||
| 648 | p = string(p, pend, "irq ", str_spec); | ||
| 649 | else if (res->flags & IORESOURCE_DMA) | ||
| 650 | p = string(p, pend, "dma ", str_spec); | ||
| 651 | else { | ||
| 652 | p = string(p, pend, "??? ", str_spec); | ||
| 653 | decode = 0; | ||
| 654 | } | ||
| 655 | hex_spec.field_width = size; | ||
| 656 | p = number(p, pend, res->start, addr ? hex_spec : dec_spec); | ||
| 657 | if (res->start != res->end) { | ||
| 658 | *p++ = '-'; | ||
| 659 | p = number(p, pend, res->end, addr ? hex_spec : dec_spec); | ||
| 660 | } | ||
| 661 | if (decode) { | ||
| 662 | if (res->flags & IORESOURCE_MEM_64) | ||
| 663 | p = string(p, pend, " 64bit", str_spec); | ||
| 664 | if (res->flags & IORESOURCE_PREFETCH) | ||
| 665 | p = string(p, pend, " pref", str_spec); | ||
| 666 | if (res->flags & IORESOURCE_DISABLED) | ||
| 667 | p = string(p, pend, " disabled", str_spec); | ||
| 668 | } else { | ||
| 669 | p = string(p, pend, " flags ", str_spec); | ||
| 670 | p = number(p, pend, res->flags, flag_spec); | ||
| 671 | } | ||
| 627 | *p++ = ']'; | 672 | *p++ = ']'; |
| 628 | *p = 0; | 673 | *p = '\0'; |
| 629 | 674 | ||
| 630 | return string(buf, end, sym, spec); | 675 | return string(buf, end, sym, spec); |
| 631 | } | 676 | } |
| @@ -636,24 +681,55 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, | |||
| 636 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; | 681 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; |
| 637 | char *p = mac_addr; | 682 | char *p = mac_addr; |
| 638 | int i; | 683 | int i; |
| 684 | char separator; | ||
| 685 | |||
| 686 | if (fmt[1] == 'F') { /* FDDI canonical format */ | ||
| 687 | separator = '-'; | ||
| 688 | } else { | ||
| 689 | separator = ':'; | ||
| 690 | } | ||
| 639 | 691 | ||
| 640 | for (i = 0; i < 6; i++) { | 692 | for (i = 0; i < 6; i++) { |
| 641 | p = pack_hex_byte(p, addr[i]); | 693 | p = pack_hex_byte(p, addr[i]); |
| 642 | if (fmt[0] == 'M' && i != 5) | 694 | if (fmt[0] == 'M' && i != 5) |
| 643 | *p++ = ':'; | 695 | *p++ = separator; |
| 644 | } | 696 | } |
| 645 | *p = '\0'; | 697 | *p = '\0'; |
| 646 | 698 | ||
| 647 | return string(buf, end, mac_addr, spec); | 699 | return string(buf, end, mac_addr, spec); |
| 648 | } | 700 | } |
| 649 | 701 | ||
| 650 | static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | 702 | static char *ip4_string(char *p, const u8 *addr, const char *fmt) |
| 651 | { | 703 | { |
| 652 | int i; | 704 | int i; |
| 653 | 705 | bool leading_zeros = (fmt[0] == 'i'); | |
| 706 | int index; | ||
| 707 | int step; | ||
| 708 | |||
| 709 | switch (fmt[2]) { | ||
| 710 | case 'h': | ||
| 711 | #ifdef __BIG_ENDIAN | ||
| 712 | index = 0; | ||
| 713 | step = 1; | ||
| 714 | #else | ||
| 715 | index = 3; | ||
| 716 | step = -1; | ||
| 717 | #endif | ||
| 718 | break; | ||
| 719 | case 'l': | ||
| 720 | index = 3; | ||
| 721 | step = -1; | ||
| 722 | break; | ||
| 723 | case 'n': | ||
| 724 | case 'b': | ||
| 725 | default: | ||
| 726 | index = 0; | ||
| 727 | step = 1; | ||
| 728 | break; | ||
| 729 | } | ||
| 654 | for (i = 0; i < 4; i++) { | 730 | for (i = 0; i < 4; i++) { |
| 655 | char temp[3]; /* hold each IP quad in reverse order */ | 731 | char temp[3]; /* hold each IP quad in reverse order */ |
| 656 | int digits = put_dec_trunc(temp, addr[i]) - temp; | 732 | int digits = put_dec_trunc(temp, addr[index]) - temp; |
| 657 | if (leading_zeros) { | 733 | if (leading_zeros) { |
| 658 | if (digits < 3) | 734 | if (digits < 3) |
| 659 | *p++ = '0'; | 735 | *p++ = '0'; |
| @@ -665,23 +741,21 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
| 665 | *p++ = temp[digits]; | 741 | *p++ = temp[digits]; |
| 666 | if (i < 3) | 742 | if (i < 3) |
| 667 | *p++ = '.'; | 743 | *p++ = '.'; |
| 744 | index += step; | ||
| 668 | } | 745 | } |
| 669 | |||
| 670 | *p = '\0'; | 746 | *p = '\0'; |
| 747 | |||
| 671 | return p; | 748 | return p; |
| 672 | } | 749 | } |
| 673 | 750 | ||
| 674 | static char *ip6_compressed_string(char *p, const char *addr) | 751 | static char *ip6_compressed_string(char *p, const char *addr) |
| 675 | { | 752 | { |
| 676 | int i; | 753 | int i, j, range; |
| 677 | int j; | ||
| 678 | int range; | ||
| 679 | unsigned char zerolength[8]; | 754 | unsigned char zerolength[8]; |
| 680 | int longest = 1; | 755 | int longest = 1; |
| 681 | int colonpos = -1; | 756 | int colonpos = -1; |
| 682 | u16 word; | 757 | u16 word; |
| 683 | u8 hi; | 758 | u8 hi, lo; |
| 684 | u8 lo; | ||
| 685 | bool needcolon = false; | 759 | bool needcolon = false; |
| 686 | bool useIPv4; | 760 | bool useIPv4; |
| 687 | struct in6_addr in6; | 761 | struct in6_addr in6; |
| @@ -735,8 +809,9 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
| 735 | p = pack_hex_byte(p, hi); | 809 | p = pack_hex_byte(p, hi); |
| 736 | else | 810 | else |
| 737 | *p++ = hex_asc_lo(hi); | 811 | *p++ = hex_asc_lo(hi); |
| 812 | p = pack_hex_byte(p, lo); | ||
| 738 | } | 813 | } |
| 739 | if (hi || lo > 0x0f) | 814 | else if (lo > 0x0f) |
| 740 | p = pack_hex_byte(p, lo); | 815 | p = pack_hex_byte(p, lo); |
| 741 | else | 816 | else |
| 742 | *p++ = hex_asc_lo(lo); | 817 | *p++ = hex_asc_lo(lo); |
| @@ -746,24 +821,25 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
| 746 | if (useIPv4) { | 821 | if (useIPv4) { |
| 747 | if (needcolon) | 822 | if (needcolon) |
| 748 | *p++ = ':'; | 823 | *p++ = ':'; |
| 749 | p = ip4_string(p, &in6.s6_addr[12], false); | 824 | p = ip4_string(p, &in6.s6_addr[12], "I4"); |
| 750 | } | 825 | } |
| 751 | |||
| 752 | *p = '\0'; | 826 | *p = '\0'; |
| 827 | |||
| 753 | return p; | 828 | return p; |
| 754 | } | 829 | } |
| 755 | 830 | ||
| 756 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 831 | static char *ip6_string(char *p, const char *addr, const char *fmt) |
| 757 | { | 832 | { |
| 758 | int i; | 833 | int i; |
| 834 | |||
| 759 | for (i = 0; i < 8; i++) { | 835 | for (i = 0; i < 8; i++) { |
| 760 | p = pack_hex_byte(p, *addr++); | 836 | p = pack_hex_byte(p, *addr++); |
| 761 | p = pack_hex_byte(p, *addr++); | 837 | p = pack_hex_byte(p, *addr++); |
| 762 | if (fmt[0] == 'I' && i != 7) | 838 | if (fmt[0] == 'I' && i != 7) |
| 763 | *p++ = ':'; | 839 | *p++ = ':'; |
| 764 | } | 840 | } |
| 765 | |||
| 766 | *p = '\0'; | 841 | *p = '\0'; |
| 842 | |||
| 767 | return p; | 843 | return p; |
| 768 | } | 844 | } |
| 769 | 845 | ||
| @@ -785,11 +861,57 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
| 785 | { | 861 | { |
| 786 | char ip4_addr[sizeof("255.255.255.255")]; | 862 | char ip4_addr[sizeof("255.255.255.255")]; |
| 787 | 863 | ||
| 788 | ip4_string(ip4_addr, addr, fmt[0] == 'i'); | 864 | ip4_string(ip4_addr, addr, fmt); |
| 789 | 865 | ||
| 790 | return string(buf, end, ip4_addr, spec); | 866 | return string(buf, end, ip4_addr, spec); |
| 791 | } | 867 | } |
| 792 | 868 | ||
| 869 | static char *uuid_string(char *buf, char *end, const u8 *addr, | ||
| 870 | struct printf_spec spec, const char *fmt) | ||
| 871 | { | ||
| 872 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | ||
| 873 | char *p = uuid; | ||
| 874 | int i; | ||
| 875 | static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
| 876 | static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; | ||
| 877 | const u8 *index = be; | ||
| 878 | bool uc = false; | ||
| 879 | |||
| 880 | switch (*(++fmt)) { | ||
| 881 | case 'L': | ||
| 882 | uc = true; /* fall-through */ | ||
| 883 | case 'l': | ||
| 884 | index = le; | ||
| 885 | break; | ||
| 886 | case 'B': | ||
| 887 | uc = true; | ||
| 888 | break; | ||
| 889 | } | ||
| 890 | |||
| 891 | for (i = 0; i < 16; i++) { | ||
| 892 | p = pack_hex_byte(p, addr[index[i]]); | ||
| 893 | switch (i) { | ||
| 894 | case 3: | ||
| 895 | case 5: | ||
| 896 | case 7: | ||
| 897 | case 9: | ||
| 898 | *p++ = '-'; | ||
| 899 | break; | ||
| 900 | } | ||
| 901 | } | ||
| 902 | |||
| 903 | *p = 0; | ||
| 904 | |||
| 905 | if (uc) { | ||
| 906 | p = uuid; | ||
| 907 | do { | ||
| 908 | *p = toupper(*p); | ||
| 909 | } while (*(++p)); | ||
| 910 | } | ||
| 911 | |||
| 912 | return string(buf, end, uuid, spec); | ||
| 913 | } | ||
| 914 | |||
| 793 | /* | 915 | /* |
| 794 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 916 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
| 795 | * by an extra set of alphanumeric characters that are extended format | 917 | * by an extra set of alphanumeric characters that are extended format |
| @@ -801,19 +923,34 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
| 801 | * - 'f' For simple symbolic function names without offset | 923 | * - 'f' For simple symbolic function names without offset |
| 802 | * - 'S' For symbolic direct pointers with offset | 924 | * - 'S' For symbolic direct pointers with offset |
| 803 | * - 's' For symbolic direct pointers without offset | 925 | * - 's' For symbolic direct pointers without offset |
| 804 | * - 'R' For a struct resource pointer, it prints the range of | 926 | * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] |
| 805 | * addresses (not the name nor the flags) | 927 | * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] |
| 806 | * - 'M' For a 6-byte MAC address, it prints the address in the | 928 | * - 'M' For a 6-byte MAC address, it prints the address in the |
| 807 | * usual colon-separated hex notation | 929 | * usual colon-separated hex notation |
| 808 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons | 930 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons |
| 931 | * - 'MF' For a 6-byte MAC FDDI address, it prints the address | ||
| 932 | * with a dash-separated hex notation | ||
| 809 | * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way | 933 | * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way |
| 810 | * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) | 934 | * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) |
| 811 | * IPv6 uses colon separated network-order 16 bit hex with leading 0's | 935 | * IPv6 uses colon separated network-order 16 bit hex with leading 0's |
| 812 | * - 'i' [46] for 'raw' IPv4/IPv6 addresses | 936 | * - 'i' [46] for 'raw' IPv4/IPv6 addresses |
| 813 | * IPv6 omits the colons (01020304...0f) | 937 | * IPv6 omits the colons (01020304...0f) |
| 814 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) | 938 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) |
| 939 | * - '[Ii]4[hnbl]' IPv4 addresses in host, network, big or little endian order | ||
| 815 | * - 'I6c' for IPv6 addresses printed as specified by | 940 | * - 'I6c' for IPv6 addresses printed as specified by |
| 816 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt | 941 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 |
| 942 | * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form | ||
| 943 | * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
| 944 | * Options for %pU are: | ||
| 945 | * b big endian lower case hex (default) | ||
| 946 | * B big endian UPPER case hex | ||
| 947 | * l little endian lower case hex | ||
| 948 | * L little endian UPPER case hex | ||
| 949 | * big endian output byte order is: | ||
| 950 | * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] | ||
| 951 | * little endian output byte order is: | ||
| 952 | * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] | ||
| 953 | * | ||
| 817 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 954 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
| 818 | * function pointers are really function descriptors, which contain a | 955 | * function pointers are really function descriptors, which contain a |
| 819 | * pointer to the real address. | 956 | * pointer to the real address. |
| @@ -828,14 +965,16 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
| 828 | case 'F': | 965 | case 'F': |
| 829 | case 'f': | 966 | case 'f': |
| 830 | ptr = dereference_function_descriptor(ptr); | 967 | ptr = dereference_function_descriptor(ptr); |
| 831 | case 's': | ||
| 832 | /* Fallthrough */ | 968 | /* Fallthrough */ |
| 833 | case 'S': | 969 | case 'S': |
| 970 | case 's': | ||
| 834 | return symbol_string(buf, end, ptr, spec, *fmt); | 971 | return symbol_string(buf, end, ptr, spec, *fmt); |
| 835 | case 'R': | 972 | case 'R': |
| 836 | return resource_string(buf, end, ptr, spec); | 973 | case 'r': |
| 974 | return resource_string(buf, end, ptr, spec, fmt); | ||
| 837 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ | 975 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ |
| 838 | case 'm': /* Contiguous: 000102030405 */ | 976 | case 'm': /* Contiguous: 000102030405 */ |
| 977 | /* [mM]F (FDDI, bit reversed) */ | ||
| 839 | return mac_address_string(buf, end, ptr, spec, fmt); | 978 | return mac_address_string(buf, end, ptr, spec, fmt); |
| 840 | case 'I': /* Formatted IP supported | 979 | case 'I': /* Formatted IP supported |
| 841 | * 4: 1.2.3.4 | 980 | * 4: 1.2.3.4 |
| @@ -853,6 +992,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
| 853 | return ip4_addr_string(buf, end, ptr, spec, fmt); | 992 | return ip4_addr_string(buf, end, ptr, spec, fmt); |
| 854 | } | 993 | } |
| 855 | break; | 994 | break; |
| 995 | case 'U': | ||
| 996 | return uuid_string(buf, end, ptr, spec, fmt); | ||
| 856 | } | 997 | } |
| 857 | spec.flags |= SMALL; | 998 | spec.flags |= SMALL; |
| 858 | if (spec.field_width == -1) { | 999 | if (spec.field_width == -1) { |
| @@ -970,8 +1111,8 @@ precision: | |||
| 970 | qualifier: | 1111 | qualifier: |
| 971 | /* get the conversion qualifier */ | 1112 | /* get the conversion qualifier */ |
| 972 | spec->qualifier = -1; | 1113 | spec->qualifier = -1; |
| 973 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1114 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
| 974 | *fmt == 'Z' || *fmt == 'z' || *fmt == 't') { | 1115 | TOLOWER(*fmt) == 'z' || *fmt == 't') { |
| 975 | spec->qualifier = *fmt++; | 1116 | spec->qualifier = *fmt++; |
| 976 | if (unlikely(spec->qualifier == *fmt)) { | 1117 | if (unlikely(spec->qualifier == *fmt)) { |
| 977 | if (spec->qualifier == 'l') { | 1118 | if (spec->qualifier == 'l') { |
| @@ -1038,7 +1179,7 @@ qualifier: | |||
| 1038 | spec->type = FORMAT_TYPE_LONG; | 1179 | spec->type = FORMAT_TYPE_LONG; |
| 1039 | else | 1180 | else |
| 1040 | spec->type = FORMAT_TYPE_ULONG; | 1181 | spec->type = FORMAT_TYPE_ULONG; |
| 1041 | } else if (spec->qualifier == 'Z' || spec->qualifier == 'z') { | 1182 | } else if (TOLOWER(spec->qualifier) == 'z') { |
| 1042 | spec->type = FORMAT_TYPE_SIZE_T; | 1183 | spec->type = FORMAT_TYPE_SIZE_T; |
| 1043 | } else if (spec->qualifier == 't') { | 1184 | } else if (spec->qualifier == 't') { |
| 1044 | spec->type = FORMAT_TYPE_PTRDIFF; | 1185 | spec->type = FORMAT_TYPE_PTRDIFF; |
| @@ -1074,7 +1215,18 @@ qualifier: | |||
| 1074 | * %ps output the name of a text symbol without offset | 1215 | * %ps output the name of a text symbol without offset |
| 1075 | * %pF output the name of a function pointer with its offset | 1216 | * %pF output the name of a function pointer with its offset |
| 1076 | * %pf output the name of a function pointer without its offset | 1217 | * %pf output the name of a function pointer without its offset |
| 1077 | * %pR output the address range in a struct resource | 1218 | * %pR output the address range in a struct resource with decoded flags |
| 1219 | * %pr output the address range in a struct resource with raw flags | ||
| 1220 | * %pM output a 6-byte MAC address with colons | ||
| 1221 | * %pm output a 6-byte MAC address without colons | ||
| 1222 | * %pI4 print an IPv4 address without leading zeros | ||
| 1223 | * %pi4 print an IPv4 address with leading zeros | ||
| 1224 | * %pI6 print an IPv6 address with colons | ||
| 1225 | * %pi6 print an IPv6 address without colons | ||
| 1226 | * %pI6c print an IPv6 address as specified by | ||
| 1227 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 | ||
| 1228 | * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper | ||
| 1229 | * case. | ||
| 1078 | * %n is ignored | 1230 | * %n is ignored |
| 1079 | * | 1231 | * |
| 1080 | * The return value is the number of characters which would | 1232 | * The return value is the number of characters which would |
| @@ -1091,8 +1243,7 @@ qualifier: | |||
| 1091 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | 1243 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
| 1092 | { | 1244 | { |
| 1093 | unsigned long long num; | 1245 | unsigned long long num; |
| 1094 | char *str, *end, c; | 1246 | char *str, *end; |
| 1095 | int read; | ||
| 1096 | struct printf_spec spec = {0}; | 1247 | struct printf_spec spec = {0}; |
| 1097 | 1248 | ||
| 1098 | /* Reject out-of-range values early. Large positive sizes are | 1249 | /* Reject out-of-range values early. Large positive sizes are |
| @@ -1111,8 +1262,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1111 | 1262 | ||
| 1112 | while (*fmt) { | 1263 | while (*fmt) { |
| 1113 | const char *old_fmt = fmt; | 1264 | const char *old_fmt = fmt; |
| 1114 | 1265 | int read = format_decode(fmt, &spec); | |
| 1115 | read = format_decode(fmt, &spec); | ||
| 1116 | 1266 | ||
| 1117 | fmt += read; | 1267 | fmt += read; |
| 1118 | 1268 | ||
| @@ -1136,7 +1286,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1136 | spec.precision = va_arg(args, int); | 1286 | spec.precision = va_arg(args, int); |
| 1137 | break; | 1287 | break; |
| 1138 | 1288 | ||
| 1139 | case FORMAT_TYPE_CHAR: | 1289 | case FORMAT_TYPE_CHAR: { |
| 1290 | char c; | ||
| 1291 | |||
| 1140 | if (!(spec.flags & LEFT)) { | 1292 | if (!(spec.flags & LEFT)) { |
| 1141 | while (--spec.field_width > 0) { | 1293 | while (--spec.field_width > 0) { |
| 1142 | if (str < end) | 1294 | if (str < end) |
| @@ -1155,6 +1307,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1155 | ++str; | 1307 | ++str; |
| 1156 | } | 1308 | } |
| 1157 | break; | 1309 | break; |
| 1310 | } | ||
| 1158 | 1311 | ||
| 1159 | case FORMAT_TYPE_STR: | 1312 | case FORMAT_TYPE_STR: |
| 1160 | str = string(str, end, va_arg(args, char *), spec); | 1313 | str = string(str, end, va_arg(args, char *), spec); |
| @@ -1185,8 +1338,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1185 | if (qualifier == 'l') { | 1338 | if (qualifier == 'l') { |
| 1186 | long *ip = va_arg(args, long *); | 1339 | long *ip = va_arg(args, long *); |
| 1187 | *ip = (str - buf); | 1340 | *ip = (str - buf); |
| 1188 | } else if (qualifier == 'Z' || | 1341 | } else if (TOLOWER(qualifier) == 'z') { |
| 1189 | qualifier == 'z') { | ||
| 1190 | size_t *ip = va_arg(args, size_t *); | 1342 | size_t *ip = va_arg(args, size_t *); |
| 1191 | *ip = (str - buf); | 1343 | *ip = (str - buf); |
| 1192 | } else { | 1344 | } else { |
| @@ -1269,7 +1421,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1269 | { | 1421 | { |
| 1270 | int i; | 1422 | int i; |
| 1271 | 1423 | ||
| 1272 | i=vsnprintf(buf,size,fmt,args); | 1424 | i = vsnprintf(buf, size, fmt, args); |
| 1425 | |||
| 1273 | return (i >= size) ? (size - 1) : i; | 1426 | return (i >= size) ? (size - 1) : i; |
| 1274 | } | 1427 | } |
| 1275 | EXPORT_SYMBOL(vscnprintf); | 1428 | EXPORT_SYMBOL(vscnprintf); |
| @@ -1288,14 +1441,15 @@ EXPORT_SYMBOL(vscnprintf); | |||
| 1288 | * | 1441 | * |
| 1289 | * See the vsnprintf() documentation for format string extensions over C99. | 1442 | * See the vsnprintf() documentation for format string extensions over C99. |
| 1290 | */ | 1443 | */ |
| 1291 | int snprintf(char * buf, size_t size, const char *fmt, ...) | 1444 | int snprintf(char *buf, size_t size, const char *fmt, ...) |
| 1292 | { | 1445 | { |
| 1293 | va_list args; | 1446 | va_list args; |
| 1294 | int i; | 1447 | int i; |
| 1295 | 1448 | ||
| 1296 | va_start(args, fmt); | 1449 | va_start(args, fmt); |
| 1297 | i=vsnprintf(buf,size,fmt,args); | 1450 | i = vsnprintf(buf, size, fmt, args); |
| 1298 | va_end(args); | 1451 | va_end(args); |
| 1452 | |||
| 1299 | return i; | 1453 | return i; |
| 1300 | } | 1454 | } |
| 1301 | EXPORT_SYMBOL(snprintf); | 1455 | EXPORT_SYMBOL(snprintf); |
| @@ -1311,7 +1465,7 @@ EXPORT_SYMBOL(snprintf); | |||
| 1311 | * the trailing '\0'. If @size is <= 0 the function returns 0. | 1465 | * the trailing '\0'. If @size is <= 0 the function returns 0. |
| 1312 | */ | 1466 | */ |
| 1313 | 1467 | ||
| 1314 | int scnprintf(char * buf, size_t size, const char *fmt, ...) | 1468 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
| 1315 | { | 1469 | { |
| 1316 | va_list args; | 1470 | va_list args; |
| 1317 | int i; | 1471 | int i; |
| @@ -1319,6 +1473,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) | |||
| 1319 | va_start(args, fmt); | 1473 | va_start(args, fmt); |
| 1320 | i = vsnprintf(buf, size, fmt, args); | 1474 | i = vsnprintf(buf, size, fmt, args); |
| 1321 | va_end(args); | 1475 | va_end(args); |
| 1476 | |||
| 1322 | return (i >= size) ? (size - 1) : i; | 1477 | return (i >= size) ? (size - 1) : i; |
| 1323 | } | 1478 | } |
| 1324 | EXPORT_SYMBOL(scnprintf); | 1479 | EXPORT_SYMBOL(scnprintf); |
| @@ -1356,14 +1511,15 @@ EXPORT_SYMBOL(vsprintf); | |||
| 1356 | * | 1511 | * |
| 1357 | * See the vsnprintf() documentation for format string extensions over C99. | 1512 | * See the vsnprintf() documentation for format string extensions over C99. |
| 1358 | */ | 1513 | */ |
| 1359 | int sprintf(char * buf, const char *fmt, ...) | 1514 | int sprintf(char *buf, const char *fmt, ...) |
| 1360 | { | 1515 | { |
| 1361 | va_list args; | 1516 | va_list args; |
| 1362 | int i; | 1517 | int i; |
| 1363 | 1518 | ||
| 1364 | va_start(args, fmt); | 1519 | va_start(args, fmt); |
| 1365 | i=vsnprintf(buf, INT_MAX, fmt, args); | 1520 | i = vsnprintf(buf, INT_MAX, fmt, args); |
| 1366 | va_end(args); | 1521 | va_end(args); |
| 1522 | |||
| 1367 | return i; | 1523 | return i; |
| 1368 | } | 1524 | } |
| 1369 | EXPORT_SYMBOL(sprintf); | 1525 | EXPORT_SYMBOL(sprintf); |
| @@ -1396,7 +1552,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args) | |||
| 1396 | { | 1552 | { |
| 1397 | struct printf_spec spec = {0}; | 1553 | struct printf_spec spec = {0}; |
| 1398 | char *str, *end; | 1554 | char *str, *end; |
| 1399 | int read; | ||
| 1400 | 1555 | ||
| 1401 | str = (char *)bin_buf; | 1556 | str = (char *)bin_buf; |
| 1402 | end = (char *)(bin_buf + size); | 1557 | end = (char *)(bin_buf + size); |
| @@ -1421,14 +1576,15 @@ do { \ | |||
| 1421 | str += sizeof(type); \ | 1576 | str += sizeof(type); \ |
| 1422 | } while (0) | 1577 | } while (0) |
| 1423 | 1578 | ||
| 1424 | |||
| 1425 | while (*fmt) { | 1579 | while (*fmt) { |
| 1426 | read = format_decode(fmt, &spec); | 1580 | int read = format_decode(fmt, &spec); |
| 1427 | 1581 | ||
| 1428 | fmt += read; | 1582 | fmt += read; |
| 1429 | 1583 | ||
| 1430 | switch (spec.type) { | 1584 | switch (spec.type) { |
| 1431 | case FORMAT_TYPE_NONE: | 1585 | case FORMAT_TYPE_NONE: |
| 1586 | case FORMAT_TYPE_INVALID: | ||
| 1587 | case FORMAT_TYPE_PERCENT_CHAR: | ||
| 1432 | break; | 1588 | break; |
| 1433 | 1589 | ||
| 1434 | case FORMAT_TYPE_WIDTH: | 1590 | case FORMAT_TYPE_WIDTH: |
| @@ -1443,13 +1599,14 @@ do { \ | |||
| 1443 | case FORMAT_TYPE_STR: { | 1599 | case FORMAT_TYPE_STR: { |
| 1444 | const char *save_str = va_arg(args, char *); | 1600 | const char *save_str = va_arg(args, char *); |
| 1445 | size_t len; | 1601 | size_t len; |
| 1602 | |||
| 1446 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE | 1603 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE |
| 1447 | || (unsigned long)save_str < PAGE_SIZE) | 1604 | || (unsigned long)save_str < PAGE_SIZE) |
| 1448 | save_str = "<NULL>"; | 1605 | save_str = "(null)"; |
| 1449 | len = strlen(save_str); | 1606 | len = strlen(save_str) + 1; |
| 1450 | if (str + len + 1 < end) | 1607 | if (str + len < end) |
| 1451 | memcpy(str, save_str, len + 1); | 1608 | memcpy(str, save_str, len); |
| 1452 | str += len + 1; | 1609 | str += len; |
| 1453 | break; | 1610 | break; |
| 1454 | } | 1611 | } |
| 1455 | 1612 | ||
| @@ -1460,19 +1617,13 @@ do { \ | |||
| 1460 | fmt++; | 1617 | fmt++; |
| 1461 | break; | 1618 | break; |
| 1462 | 1619 | ||
| 1463 | case FORMAT_TYPE_PERCENT_CHAR: | ||
| 1464 | break; | ||
| 1465 | |||
| 1466 | case FORMAT_TYPE_INVALID: | ||
| 1467 | break; | ||
| 1468 | |||
| 1469 | case FORMAT_TYPE_NRCHARS: { | 1620 | case FORMAT_TYPE_NRCHARS: { |
| 1470 | /* skip %n 's argument */ | 1621 | /* skip %n 's argument */ |
| 1471 | int qualifier = spec.qualifier; | 1622 | int qualifier = spec.qualifier; |
| 1472 | void *skip_arg; | 1623 | void *skip_arg; |
| 1473 | if (qualifier == 'l') | 1624 | if (qualifier == 'l') |
| 1474 | skip_arg = va_arg(args, long *); | 1625 | skip_arg = va_arg(args, long *); |
| 1475 | else if (qualifier == 'Z' || qualifier == 'z') | 1626 | else if (TOLOWER(qualifier) == 'z') |
| 1476 | skip_arg = va_arg(args, size_t *); | 1627 | skip_arg = va_arg(args, size_t *); |
| 1477 | else | 1628 | else |
| 1478 | skip_arg = va_arg(args, int *); | 1629 | skip_arg = va_arg(args, int *); |
| @@ -1508,8 +1659,8 @@ do { \ | |||
| 1508 | } | 1659 | } |
| 1509 | } | 1660 | } |
| 1510 | } | 1661 | } |
| 1511 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
| 1512 | 1662 | ||
| 1663 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
| 1513 | #undef save_arg | 1664 | #undef save_arg |
| 1514 | } | 1665 | } |
| 1515 | EXPORT_SYMBOL_GPL(vbin_printf); | 1666 | EXPORT_SYMBOL_GPL(vbin_printf); |
| @@ -1538,11 +1689,9 @@ EXPORT_SYMBOL_GPL(vbin_printf); | |||
| 1538 | */ | 1689 | */ |
| 1539 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | 1690 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) |
| 1540 | { | 1691 | { |
| 1541 | unsigned long long num; | ||
| 1542 | char *str, *end, c; | ||
| 1543 | const char *args = (const char *)bin_buf; | ||
| 1544 | |||
| 1545 | struct printf_spec spec = {0}; | 1692 | struct printf_spec spec = {0}; |
| 1693 | char *str, *end; | ||
| 1694 | const char *args = (const char *)bin_buf; | ||
| 1546 | 1695 | ||
| 1547 | if (WARN_ON_ONCE((int) size < 0)) | 1696 | if (WARN_ON_ONCE((int) size < 0)) |
| 1548 | return 0; | 1697 | return 0; |
| @@ -1572,10 +1721,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 1572 | } | 1721 | } |
| 1573 | 1722 | ||
| 1574 | while (*fmt) { | 1723 | while (*fmt) { |
| 1575 | int read; | ||
| 1576 | const char *old_fmt = fmt; | 1724 | const char *old_fmt = fmt; |
| 1577 | 1725 | int read = format_decode(fmt, &spec); | |
| 1578 | read = format_decode(fmt, &spec); | ||
| 1579 | 1726 | ||
| 1580 | fmt += read; | 1727 | fmt += read; |
| 1581 | 1728 | ||
| @@ -1599,7 +1746,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 1599 | spec.precision = get_arg(int); | 1746 | spec.precision = get_arg(int); |
| 1600 | break; | 1747 | break; |
| 1601 | 1748 | ||
| 1602 | case FORMAT_TYPE_CHAR: | 1749 | case FORMAT_TYPE_CHAR: { |
| 1750 | char c; | ||
| 1751 | |||
| 1603 | if (!(spec.flags & LEFT)) { | 1752 | if (!(spec.flags & LEFT)) { |
| 1604 | while (--spec.field_width > 0) { | 1753 | while (--spec.field_width > 0) { |
| 1605 | if (str < end) | 1754 | if (str < end) |
| @@ -1617,11 +1766,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 1617 | ++str; | 1766 | ++str; |
| 1618 | } | 1767 | } |
| 1619 | break; | 1768 | break; |
| 1769 | } | ||
| 1620 | 1770 | ||
| 1621 | case FORMAT_TYPE_STR: { | 1771 | case FORMAT_TYPE_STR: { |
| 1622 | const char *str_arg = args; | 1772 | const char *str_arg = args; |
| 1623 | size_t len = strlen(str_arg); | 1773 | args += strlen(str_arg) + 1; |
| 1624 | args += len + 1; | ||
| 1625 | str = string(str, end, (char *)str_arg, spec); | 1774 | str = string(str, end, (char *)str_arg, spec); |
| 1626 | break; | 1775 | break; |
| 1627 | } | 1776 | } |
| @@ -1633,11 +1782,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 1633 | break; | 1782 | break; |
| 1634 | 1783 | ||
| 1635 | case FORMAT_TYPE_PERCENT_CHAR: | 1784 | case FORMAT_TYPE_PERCENT_CHAR: |
| 1636 | if (str < end) | ||
| 1637 | *str = '%'; | ||
| 1638 | ++str; | ||
| 1639 | break; | ||
| 1640 | |||
| 1641 | case FORMAT_TYPE_INVALID: | 1785 | case FORMAT_TYPE_INVALID: |
| 1642 | if (str < end) | 1786 | if (str < end) |
| 1643 | *str = '%'; | 1787 | *str = '%'; |
| @@ -1648,15 +1792,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 1648 | /* skip */ | 1792 | /* skip */ |
| 1649 | break; | 1793 | break; |
| 1650 | 1794 | ||
| 1651 | default: | 1795 | default: { |
| 1796 | unsigned long long num; | ||
| 1797 | |||
| 1652 | switch (spec.type) { | 1798 | switch (spec.type) { |
| 1653 | 1799 | ||
| 1654 | case FORMAT_TYPE_LONG_LONG: | 1800 | case FORMAT_TYPE_LONG_LONG: |
| 1655 | num = get_arg(long long); | 1801 | num = get_arg(long long); |
| 1656 | break; | 1802 | break; |
| 1657 | case FORMAT_TYPE_ULONG: | 1803 | case FORMAT_TYPE_ULONG: |
| 1658 | num = get_arg(unsigned long); | ||
| 1659 | break; | ||
| 1660 | case FORMAT_TYPE_LONG: | 1804 | case FORMAT_TYPE_LONG: |
| 1661 | num = get_arg(unsigned long); | 1805 | num = get_arg(unsigned long); |
| 1662 | break; | 1806 | break; |
| @@ -1686,8 +1830,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 1686 | } | 1830 | } |
| 1687 | 1831 | ||
| 1688 | str = number(str, end, num, spec); | 1832 | str = number(str, end, num, spec); |
| 1689 | } | 1833 | } /* default: */ |
| 1690 | } | 1834 | } /* switch(spec.type) */ |
| 1835 | } /* while(*fmt) */ | ||
| 1691 | 1836 | ||
| 1692 | if (size > 0) { | 1837 | if (size > 0) { |
| 1693 | if (str < end) | 1838 | if (str < end) |
| @@ -1721,6 +1866,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) | |||
| 1721 | va_start(args, fmt); | 1866 | va_start(args, fmt); |
| 1722 | ret = vbin_printf(bin_buf, size, fmt, args); | 1867 | ret = vbin_printf(bin_buf, size, fmt, args); |
| 1723 | va_end(args); | 1868 | va_end(args); |
| 1869 | |||
| 1724 | return ret; | 1870 | return ret; |
| 1725 | } | 1871 | } |
| 1726 | EXPORT_SYMBOL_GPL(bprintf); | 1872 | EXPORT_SYMBOL_GPL(bprintf); |
| @@ -1733,27 +1879,23 @@ EXPORT_SYMBOL_GPL(bprintf); | |||
| 1733 | * @fmt: format of buffer | 1879 | * @fmt: format of buffer |
| 1734 | * @args: arguments | 1880 | * @args: arguments |
| 1735 | */ | 1881 | */ |
| 1736 | int vsscanf(const char * buf, const char * fmt, va_list args) | 1882 | int vsscanf(const char *buf, const char *fmt, va_list args) |
| 1737 | { | 1883 | { |
| 1738 | const char *str = buf; | 1884 | const char *str = buf; |
| 1739 | char *next; | 1885 | char *next; |
| 1740 | char digit; | 1886 | char digit; |
| 1741 | int num = 0; | 1887 | int num = 0; |
| 1742 | int qualifier; | 1888 | int qualifier, base, field_width; |
| 1743 | int base; | 1889 | bool is_sign; |
| 1744 | int field_width; | ||
| 1745 | int is_sign = 0; | ||
| 1746 | 1890 | ||
| 1747 | while(*fmt && *str) { | 1891 | while (*fmt && *str) { |
| 1748 | /* skip any white space in format */ | 1892 | /* skip any white space in format */ |
| 1749 | /* white space in format matchs any amount of | 1893 | /* white space in format matchs any amount of |
| 1750 | * white space, including none, in the input. | 1894 | * white space, including none, in the input. |
| 1751 | */ | 1895 | */ |
| 1752 | if (isspace(*fmt)) { | 1896 | if (isspace(*fmt)) { |
| 1753 | while (isspace(*fmt)) | 1897 | fmt = skip_spaces(++fmt); |
| 1754 | ++fmt; | 1898 | str = skip_spaces(str); |
| 1755 | while (isspace(*str)) | ||
| 1756 | ++str; | ||
| 1757 | } | 1899 | } |
| 1758 | 1900 | ||
| 1759 | /* anything that is not a conversion must match exactly */ | 1901 | /* anything that is not a conversion must match exactly */ |
| @@ -1766,7 +1908,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1766 | if (!*fmt) | 1908 | if (!*fmt) |
| 1767 | break; | 1909 | break; |
| 1768 | ++fmt; | 1910 | ++fmt; |
| 1769 | 1911 | ||
| 1770 | /* skip this conversion. | 1912 | /* skip this conversion. |
| 1771 | * advance both strings to next white space | 1913 | * advance both strings to next white space |
| 1772 | */ | 1914 | */ |
| @@ -1785,8 +1927,8 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1785 | 1927 | ||
| 1786 | /* get conversion qualifier */ | 1928 | /* get conversion qualifier */ |
| 1787 | qualifier = -1; | 1929 | qualifier = -1; |
| 1788 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1930 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
| 1789 | *fmt == 'Z' || *fmt == 'z') { | 1931 | TOLOWER(*fmt) == 'z') { |
| 1790 | qualifier = *fmt++; | 1932 | qualifier = *fmt++; |
| 1791 | if (unlikely(qualifier == *fmt)) { | 1933 | if (unlikely(qualifier == *fmt)) { |
| 1792 | if (qualifier == 'h') { | 1934 | if (qualifier == 'h') { |
| @@ -1798,16 +1940,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1798 | } | 1940 | } |
| 1799 | } | 1941 | } |
| 1800 | } | 1942 | } |
| 1801 | base = 10; | ||
| 1802 | is_sign = 0; | ||
| 1803 | 1943 | ||
| 1804 | if (!*fmt || !*str) | 1944 | if (!*fmt || !*str) |
| 1805 | break; | 1945 | break; |
| 1806 | 1946 | ||
| 1807 | switch(*fmt++) { | 1947 | base = 10; |
| 1948 | is_sign = 0; | ||
| 1949 | |||
| 1950 | switch (*fmt++) { | ||
| 1808 | case 'c': | 1951 | case 'c': |
| 1809 | { | 1952 | { |
| 1810 | char *s = (char *) va_arg(args,char*); | 1953 | char *s = (char *)va_arg(args, char*); |
| 1811 | if (field_width == -1) | 1954 | if (field_width == -1) |
| 1812 | field_width = 1; | 1955 | field_width = 1; |
| 1813 | do { | 1956 | do { |
| @@ -1818,17 +1961,15 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1818 | continue; | 1961 | continue; |
| 1819 | case 's': | 1962 | case 's': |
| 1820 | { | 1963 | { |
| 1821 | char *s = (char *) va_arg(args, char *); | 1964 | char *s = (char *)va_arg(args, char *); |
| 1822 | if(field_width == -1) | 1965 | if (field_width == -1) |
| 1823 | field_width = INT_MAX; | 1966 | field_width = INT_MAX; |
| 1824 | /* first, skip leading white space in buffer */ | 1967 | /* first, skip leading white space in buffer */ |
| 1825 | while (isspace(*str)) | 1968 | str = skip_spaces(str); |
| 1826 | str++; | ||
| 1827 | 1969 | ||
| 1828 | /* now copy until next white space */ | 1970 | /* now copy until next white space */ |
| 1829 | while (*str && !isspace(*str) && field_width--) { | 1971 | while (*str && !isspace(*str) && field_width--) |
| 1830 | *s++ = *str++; | 1972 | *s++ = *str++; |
| 1831 | } | ||
| 1832 | *s = '\0'; | 1973 | *s = '\0'; |
| 1833 | num++; | 1974 | num++; |
| 1834 | } | 1975 | } |
| @@ -1836,7 +1977,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1836 | case 'n': | 1977 | case 'n': |
| 1837 | /* return number of characters read so far */ | 1978 | /* return number of characters read so far */ |
| 1838 | { | 1979 | { |
| 1839 | int *i = (int *)va_arg(args,int*); | 1980 | int *i = (int *)va_arg(args, int*); |
| 1840 | *i = str - buf; | 1981 | *i = str - buf; |
| 1841 | } | 1982 | } |
| 1842 | continue; | 1983 | continue; |
| @@ -1848,14 +1989,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1848 | base = 16; | 1989 | base = 16; |
| 1849 | break; | 1990 | break; |
| 1850 | case 'i': | 1991 | case 'i': |
| 1851 | base = 0; | 1992 | base = 0; |
| 1852 | case 'd': | 1993 | case 'd': |
| 1853 | is_sign = 1; | 1994 | is_sign = 1; |
| 1854 | case 'u': | 1995 | case 'u': |
| 1855 | break; | 1996 | break; |
| 1856 | case '%': | 1997 | case '%': |
| 1857 | /* looking for '%' in str */ | 1998 | /* looking for '%' in str */ |
| 1858 | if (*str++ != '%') | 1999 | if (*str++ != '%') |
| 1859 | return num; | 2000 | return num; |
| 1860 | continue; | 2001 | continue; |
| 1861 | default: | 2002 | default: |
| @@ -1866,71 +2007,70 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
| 1866 | /* have some sort of integer conversion. | 2007 | /* have some sort of integer conversion. |
| 1867 | * first, skip white space in buffer. | 2008 | * first, skip white space in buffer. |
| 1868 | */ | 2009 | */ |
| 1869 | while (isspace(*str)) | 2010 | str = skip_spaces(str); |
| 1870 | str++; | ||
| 1871 | 2011 | ||
| 1872 | digit = *str; | 2012 | digit = *str; |
| 1873 | if (is_sign && digit == '-') | 2013 | if (is_sign && digit == '-') |
| 1874 | digit = *(str + 1); | 2014 | digit = *(str + 1); |
| 1875 | 2015 | ||
| 1876 | if (!digit | 2016 | if (!digit |
| 1877 | || (base == 16 && !isxdigit(digit)) | 2017 | || (base == 16 && !isxdigit(digit)) |
| 1878 | || (base == 10 && !isdigit(digit)) | 2018 | || (base == 10 && !isdigit(digit)) |
| 1879 | || (base == 8 && (!isdigit(digit) || digit > '7')) | 2019 | || (base == 8 && (!isdigit(digit) || digit > '7')) |
| 1880 | || (base == 0 && !isdigit(digit))) | 2020 | || (base == 0 && !isdigit(digit))) |
| 1881 | break; | 2021 | break; |
| 1882 | 2022 | ||
| 1883 | switch(qualifier) { | 2023 | switch (qualifier) { |
| 1884 | case 'H': /* that's 'hh' in format */ | 2024 | case 'H': /* that's 'hh' in format */ |
| 1885 | if (is_sign) { | 2025 | if (is_sign) { |
| 1886 | signed char *s = (signed char *) va_arg(args,signed char *); | 2026 | signed char *s = (signed char *)va_arg(args, signed char *); |
| 1887 | *s = (signed char) simple_strtol(str,&next,base); | 2027 | *s = (signed char)simple_strtol(str, &next, base); |
| 1888 | } else { | 2028 | } else { |
| 1889 | unsigned char *s = (unsigned char *) va_arg(args, unsigned char *); | 2029 | unsigned char *s = (unsigned char *)va_arg(args, unsigned char *); |
| 1890 | *s = (unsigned char) simple_strtoul(str, &next, base); | 2030 | *s = (unsigned char)simple_strtoul(str, &next, base); |
| 1891 | } | 2031 | } |
| 1892 | break; | 2032 | break; |
| 1893 | case 'h': | 2033 | case 'h': |
| 1894 | if (is_sign) { | 2034 | if (is_sign) { |
| 1895 | short *s = (short *) va_arg(args,short *); | 2035 | short *s = (short *)va_arg(args, short *); |
| 1896 | *s = (short) simple_strtol(str,&next,base); | 2036 | *s = (short)simple_strtol(str, &next, base); |
| 1897 | } else { | 2037 | } else { |
| 1898 | unsigned short *s = (unsigned short *) va_arg(args, unsigned short *); | 2038 | unsigned short *s = (unsigned short *)va_arg(args, unsigned short *); |
| 1899 | *s = (unsigned short) simple_strtoul(str, &next, base); | 2039 | *s = (unsigned short)simple_strtoul(str, &next, base); |
| 1900 | } | 2040 | } |
| 1901 | break; | 2041 | break; |
| 1902 | case 'l': | 2042 | case 'l': |
| 1903 | if (is_sign) { | 2043 | if (is_sign) { |
| 1904 | long *l = (long *) va_arg(args,long *); | 2044 | long *l = (long *)va_arg(args, long *); |
| 1905 | *l = simple_strtol(str,&next,base); | 2045 | *l = simple_strtol(str, &next, base); |
| 1906 | } else { | 2046 | } else { |
| 1907 | unsigned long *l = (unsigned long*) va_arg(args,unsigned long*); | 2047 | unsigned long *l = (unsigned long *)va_arg(args, unsigned long *); |
| 1908 | *l = simple_strtoul(str,&next,base); | 2048 | *l = simple_strtoul(str, &next, base); |
| 1909 | } | 2049 | } |
| 1910 | break; | 2050 | break; |
| 1911 | case 'L': | 2051 | case 'L': |
| 1912 | if (is_sign) { | 2052 | if (is_sign) { |
| 1913 | long long *l = (long long*) va_arg(args,long long *); | 2053 | long long *l = (long long *)va_arg(args, long long *); |
| 1914 | *l = simple_strtoll(str,&next,base); | 2054 | *l = simple_strtoll(str, &next, base); |
| 1915 | } else { | 2055 | } else { |
| 1916 | unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*); | 2056 | unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *); |
| 1917 | *l = simple_strtoull(str,&next,base); | 2057 | *l = simple_strtoull(str, &next, base); |
| 1918 | } | 2058 | } |
| 1919 | break; | 2059 | break; |
| 1920 | case 'Z': | 2060 | case 'Z': |
| 1921 | case 'z': | 2061 | case 'z': |
| 1922 | { | 2062 | { |
| 1923 | size_t *s = (size_t*) va_arg(args,size_t*); | 2063 | size_t *s = (size_t *)va_arg(args, size_t *); |
| 1924 | *s = (size_t) simple_strtoul(str,&next,base); | 2064 | *s = (size_t)simple_strtoul(str, &next, base); |
| 1925 | } | 2065 | } |
| 1926 | break; | 2066 | break; |
| 1927 | default: | 2067 | default: |
| 1928 | if (is_sign) { | 2068 | if (is_sign) { |
| 1929 | int *i = (int *) va_arg(args, int*); | 2069 | int *i = (int *)va_arg(args, int *); |
| 1930 | *i = (int) simple_strtol(str,&next,base); | 2070 | *i = (int)simple_strtol(str, &next, base); |
| 1931 | } else { | 2071 | } else { |
| 1932 | unsigned int *i = (unsigned int*) va_arg(args, unsigned int*); | 2072 | unsigned int *i = (unsigned int *)va_arg(args, unsigned int*); |
| 1933 | *i = (unsigned int) simple_strtoul(str,&next,base); | 2073 | *i = (unsigned int)simple_strtoul(str, &next, base); |
| 1934 | } | 2074 | } |
| 1935 | break; | 2075 | break; |
| 1936 | } | 2076 | } |
| @@ -1961,14 +2101,15 @@ EXPORT_SYMBOL(vsscanf); | |||
| 1961 | * @fmt: formatting of buffer | 2101 | * @fmt: formatting of buffer |
| 1962 | * @...: resulting arguments | 2102 | * @...: resulting arguments |
| 1963 | */ | 2103 | */ |
| 1964 | int sscanf(const char * buf, const char * fmt, ...) | 2104 | int sscanf(const char *buf, const char *fmt, ...) |
| 1965 | { | 2105 | { |
| 1966 | va_list args; | 2106 | va_list args; |
| 1967 | int i; | 2107 | int i; |
| 1968 | 2108 | ||
| 1969 | va_start(args,fmt); | 2109 | va_start(args, fmt); |
| 1970 | i = vsscanf(buf,fmt,args); | 2110 | i = vsscanf(buf, fmt, args); |
| 1971 | va_end(args); | 2111 | va_end(args); |
| 2112 | |||
| 1972 | return i; | 2113 | return i; |
| 1973 | } | 2114 | } |
| 1974 | EXPORT_SYMBOL(sscanf); | 2115 | EXPORT_SYMBOL(sscanf); |
