diff options
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 590 |
1 files changed, 374 insertions, 216 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 33bed5e67a21..46d34b0b74a8 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,10 +113,12 @@ 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 | } |
121 | EXPORT_SYMBOL(simple_strtoll); | ||
139 | 122 | ||
140 | /** | 123 | /** |
141 | * strict_strtoul - convert a string to an unsigned long strictly | 124 | * strict_strtoul - convert a string to an unsigned long strictly |
@@ -173,6 +156,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) | |||
173 | val = simple_strtoul(cp, &tail, base); | 156 | val = simple_strtoul(cp, &tail, base); |
174 | if (tail == cp) | 157 | if (tail == cp) |
175 | return -EINVAL; | 158 | return -EINVAL; |
159 | |||
176 | if ((*tail == '\0') || | 160 | if ((*tail == '\0') || |
177 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | 161 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { |
178 | *res = val; | 162 | *res = val; |
@@ -285,10 +269,11 @@ EXPORT_SYMBOL(strict_strtoll); | |||
285 | 269 | ||
286 | static int skip_atoi(const char **s) | 270 | static int skip_atoi(const char **s) |
287 | { | 271 | { |
288 | int i=0; | 272 | int i = 0; |
289 | 273 | ||
290 | while (isdigit(**s)) | 274 | while (isdigit(**s)) |
291 | i = i*10 + *((*s)++) - '0'; | 275 | i = i*10 + *((*s)++) - '0'; |
276 | |||
292 | return i; | 277 | return i; |
293 | } | 278 | } |
294 | 279 | ||
@@ -302,7 +287,7 @@ static int skip_atoi(const char **s) | |||
302 | /* Formats correctly any integer in [0,99999]. | 287 | /* Formats correctly any integer in [0,99999]. |
303 | * Outputs from one to five digits depending on input. | 288 | * Outputs from one to five digits depending on input. |
304 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 289 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
305 | static char* put_dec_trunc(char *buf, unsigned q) | 290 | static char *put_dec_trunc(char *buf, unsigned q) |
306 | { | 291 | { |
307 | unsigned d3, d2, d1, d0; | 292 | unsigned d3, d2, d1, d0; |
308 | d1 = (q>>4) & 0xf; | 293 | d1 = (q>>4) & 0xf; |
@@ -331,14 +316,15 @@ static char* put_dec_trunc(char *buf, unsigned q) | |||
331 | d3 = d3 - 10*q; | 316 | d3 = d3 - 10*q; |
332 | *buf++ = d3 + '0'; /* next digit */ | 317 | *buf++ = d3 + '0'; /* next digit */ |
333 | if (q != 0) | 318 | if (q != 0) |
334 | *buf++ = q + '0'; /* most sign. digit */ | 319 | *buf++ = q + '0'; /* most sign. digit */ |
335 | } | 320 | } |
336 | } | 321 | } |
337 | } | 322 | } |
323 | |||
338 | return buf; | 324 | return buf; |
339 | } | 325 | } |
340 | /* Same with if's removed. Always emits five digits */ | 326 | /* Same with if's removed. Always emits five digits */ |
341 | static char* put_dec_full(char *buf, unsigned q) | 327 | static char *put_dec_full(char *buf, unsigned q) |
342 | { | 328 | { |
343 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 329 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
344 | /* but anyway, gcc produces better code with full-sized ints */ | 330 | /* but anyway, gcc produces better code with full-sized ints */ |
@@ -347,14 +333,15 @@ static char* put_dec_full(char *buf, unsigned q) | |||
347 | d2 = (q>>8) & 0xf; | 333 | d2 = (q>>8) & 0xf; |
348 | d3 = (q>>12); | 334 | d3 = (q>>12); |
349 | 335 | ||
350 | /* Possible ways to approx. divide by 10 */ | 336 | /* |
351 | /* gcc -O2 replaces multiply with shifts and adds */ | 337 | * Possible ways to approx. divide by 10 |
352 | // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) | 338 | * gcc -O2 replaces multiply with shifts and adds |
353 | // (x * 0x67) >> 10: 1100111 | 339 | * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) |
354 | // (x * 0x34) >> 9: 110100 - same | 340 | * (x * 0x67) >> 10: 1100111 |
355 | // (x * 0x1a) >> 8: 11010 - same | 341 | * (x * 0x34) >> 9: 110100 - same |
356 | // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | 342 | * (x * 0x1a) >> 8: 11010 - same |
357 | 343 | * (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | |
344 | */ | ||
358 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); | 345 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); |
359 | q = (d0 * 0xcd) >> 11; | 346 | q = (d0 * 0xcd) >> 11; |
360 | d0 = d0 - 10*q; | 347 | d0 = d0 - 10*q; |
@@ -375,10 +362,11 @@ static char* put_dec_full(char *buf, unsigned q) | |||
375 | d3 = d3 - 10*q; | 362 | d3 = d3 - 10*q; |
376 | *buf++ = d3 + '0'; | 363 | *buf++ = d3 + '0'; |
377 | *buf++ = q + '0'; | 364 | *buf++ = q + '0'; |
365 | |||
378 | return buf; | 366 | return buf; |
379 | } | 367 | } |
380 | /* No inlining helps gcc to use registers better */ | 368 | /* No inlining helps gcc to use registers better */ |
381 | static noinline char* put_dec(char *buf, unsigned long long num) | 369 | static noinline char *put_dec(char *buf, unsigned long long num) |
382 | { | 370 | { |
383 | while (1) { | 371 | while (1) { |
384 | unsigned rem; | 372 | unsigned rem; |
@@ -394,8 +382,8 @@ static noinline char* put_dec(char *buf, unsigned long long num) | |||
394 | #define PLUS 4 /* show plus */ | 382 | #define PLUS 4 /* show plus */ |
395 | #define SPACE 8 /* space if plus */ | 383 | #define SPACE 8 /* space if plus */ |
396 | #define LEFT 16 /* left justified */ | 384 | #define LEFT 16 /* left justified */ |
397 | #define SMALL 32 /* Must be 32 == 0x20 */ | 385 | #define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */ |
398 | #define SPECIAL 64 /* 0x */ | 386 | #define SPECIAL 64 /* prefix hex with "0x", octal with "0" */ |
399 | 387 | ||
400 | enum format_type { | 388 | enum format_type { |
401 | FORMAT_TYPE_NONE, /* Just a string part */ | 389 | FORMAT_TYPE_NONE, /* Just a string part */ |
@@ -421,12 +409,12 @@ enum format_type { | |||
421 | }; | 409 | }; |
422 | 410 | ||
423 | struct printf_spec { | 411 | struct printf_spec { |
424 | enum format_type type; | 412 | u8 type; /* format_type enum */ |
425 | int flags; /* flags to number() */ | 413 | u8 flags; /* flags to number() */ |
426 | int field_width; /* width of output field */ | 414 | u8 base; /* number base, 8, 10 or 16 only */ |
427 | int base; | 415 | u8 qualifier; /* number qualifier, one of 'hHlLtzZ' */ |
428 | int precision; /* # of digits/chars */ | 416 | s16 field_width; /* width of output field */ |
429 | int qualifier; | 417 | s16 precision; /* # of digits/chars */ |
430 | }; | 418 | }; |
431 | 419 | ||
432 | static char *number(char *buf, char *end, unsigned long long num, | 420 | static char *number(char *buf, char *end, unsigned long long num, |
@@ -448,9 +436,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
448 | spec.flags &= ~ZEROPAD; | 436 | spec.flags &= ~ZEROPAD; |
449 | sign = 0; | 437 | sign = 0; |
450 | if (spec.flags & SIGN) { | 438 | if (spec.flags & SIGN) { |
451 | if ((signed long long) num < 0) { | 439 | if ((signed long long)num < 0) { |
452 | sign = '-'; | 440 | sign = '-'; |
453 | num = - (signed long long) num; | 441 | num = -(signed long long)num; |
454 | spec.field_width--; | 442 | spec.field_width--; |
455 | } else if (spec.flags & PLUS) { | 443 | } else if (spec.flags & PLUS) { |
456 | sign = '+'; | 444 | sign = '+'; |
@@ -478,7 +466,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
478 | else if (spec.base != 10) { /* 8 or 16 */ | 466 | else if (spec.base != 10) { /* 8 or 16 */ |
479 | int mask = spec.base - 1; | 467 | int mask = spec.base - 1; |
480 | int shift = 3; | 468 | int shift = 3; |
481 | if (spec.base == 16) shift = 4; | 469 | |
470 | if (spec.base == 16) | ||
471 | shift = 4; | ||
482 | do { | 472 | do { |
483 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); | 473 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); |
484 | num >>= shift; | 474 | num >>= shift; |
@@ -493,7 +483,7 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
493 | /* leading space padding */ | 483 | /* leading space padding */ |
494 | spec.field_width -= spec.precision; | 484 | spec.field_width -= spec.precision; |
495 | if (!(spec.flags & (ZEROPAD+LEFT))) { | 485 | if (!(spec.flags & (ZEROPAD+LEFT))) { |
496 | while(--spec.field_width >= 0) { | 486 | while (--spec.field_width >= 0) { |
497 | if (buf < end) | 487 | if (buf < end) |
498 | *buf = ' '; | 488 | *buf = ' '; |
499 | ++buf; | 489 | ++buf; |
@@ -543,15 +533,16 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
543 | *buf = ' '; | 533 | *buf = ' '; |
544 | ++buf; | 534 | ++buf; |
545 | } | 535 | } |
536 | |||
546 | return buf; | 537 | return buf; |
547 | } | 538 | } |
548 | 539 | ||
549 | static char *string(char *buf, char *end, char *s, struct printf_spec spec) | 540 | static char *string(char *buf, char *end, const char *s, struct printf_spec spec) |
550 | { | 541 | { |
551 | int len, i; | 542 | int len, i; |
552 | 543 | ||
553 | if ((unsigned long)s < PAGE_SIZE) | 544 | if ((unsigned long)s < PAGE_SIZE) |
554 | s = "<NULL>"; | 545 | s = "(null)"; |
555 | 546 | ||
556 | len = strnlen(s, spec.precision); | 547 | len = strnlen(s, spec.precision); |
557 | 548 | ||
@@ -572,6 +563,7 @@ static char *string(char *buf, char *end, char *s, struct printf_spec spec) | |||
572 | *buf = ' '; | 563 | *buf = ' '; |
573 | ++buf; | 564 | ++buf; |
574 | } | 565 | } |
566 | |||
575 | return buf; | 567 | return buf; |
576 | } | 568 | } |
577 | 569 | ||
@@ -585,47 +577,115 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
585 | sprint_symbol(sym, value); | 577 | sprint_symbol(sym, value); |
586 | else | 578 | else |
587 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | 579 | kallsyms_lookup(value, NULL, NULL, NULL, sym); |
580 | |||
588 | return string(buf, end, sym, spec); | 581 | return string(buf, end, sym, spec); |
589 | #else | 582 | #else |
590 | spec.field_width = 2*sizeof(void *); | 583 | spec.field_width = 2 * sizeof(void *); |
591 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | 584 | spec.flags |= SPECIAL | SMALL | ZEROPAD; |
592 | spec.base = 16; | 585 | spec.base = 16; |
586 | |||
593 | return number(buf, end, value, spec); | 587 | return number(buf, end, value, spec); |
594 | #endif | 588 | #endif |
595 | } | 589 | } |
596 | 590 | ||
597 | static char *resource_string(char *buf, char *end, struct resource *res, | 591 | static char *resource_string(char *buf, char *end, struct resource *res, |
598 | struct printf_spec spec) | 592 | struct printf_spec spec, const char *fmt) |
599 | { | 593 | { |
600 | #ifndef IO_RSRC_PRINTK_SIZE | 594 | #ifndef IO_RSRC_PRINTK_SIZE |
601 | #define IO_RSRC_PRINTK_SIZE 4 | 595 | #define IO_RSRC_PRINTK_SIZE 6 |
602 | #endif | 596 | #endif |
603 | 597 | ||
604 | #ifndef MEM_RSRC_PRINTK_SIZE | 598 | #ifndef MEM_RSRC_PRINTK_SIZE |
605 | #define MEM_RSRC_PRINTK_SIZE 8 | 599 | #define MEM_RSRC_PRINTK_SIZE 10 |
606 | #endif | 600 | #endif |
607 | struct printf_spec num_spec = { | 601 | static const struct printf_spec io_spec = { |
608 | .base = 16, | 602 | .base = 16, |
603 | .field_width = IO_RSRC_PRINTK_SIZE, | ||
609 | .precision = -1, | 604 | .precision = -1, |
610 | .flags = SPECIAL | SMALL | ZEROPAD, | 605 | .flags = SPECIAL | SMALL | ZEROPAD, |
611 | }; | 606 | }; |
612 | /* room for the actual numbers, the two "0x", -, [, ] and the final zero */ | 607 | static const struct printf_spec mem_spec = { |
613 | char sym[4*sizeof(resource_size_t) + 8]; | 608 | .base = 16, |
614 | char *p = sym, *pend = sym + sizeof(sym); | 609 | .field_width = MEM_RSRC_PRINTK_SIZE, |
615 | int size = -1; | 610 | .precision = -1, |
611 | .flags = SPECIAL | SMALL | ZEROPAD, | ||
612 | }; | ||
613 | static const struct printf_spec bus_spec = { | ||
614 | .base = 16, | ||
615 | .field_width = 2, | ||
616 | .precision = -1, | ||
617 | .flags = SMALL | ZEROPAD, | ||
618 | }; | ||
619 | static const struct printf_spec dec_spec = { | ||
620 | .base = 10, | ||
621 | .precision = -1, | ||
622 | .flags = 0, | ||
623 | }; | ||
624 | static const struct printf_spec str_spec = { | ||
625 | .field_width = -1, | ||
626 | .precision = 10, | ||
627 | .flags = LEFT, | ||
628 | }; | ||
629 | static const struct printf_spec flag_spec = { | ||
630 | .base = 16, | ||
631 | .precision = -1, | ||
632 | .flags = SPECIAL | SMALL, | ||
633 | }; | ||
616 | 634 | ||
617 | if (res->flags & IORESOURCE_IO) | 635 | /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8) |
618 | size = IO_RSRC_PRINTK_SIZE; | 636 | * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */ |
619 | else if (res->flags & IORESOURCE_MEM) | 637 | #define RSRC_BUF_SIZE ((2 * sizeof(resource_size_t)) + 4) |
620 | size = MEM_RSRC_PRINTK_SIZE; | 638 | #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) |
639 | #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") | ||
640 | #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") | ||
641 | char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, | ||
642 | 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; | ||
643 | |||
644 | char *p = sym, *pend = sym + sizeof(sym); | ||
645 | int decode = (fmt[0] == 'R') ? 1 : 0; | ||
646 | const struct printf_spec *specp; | ||
621 | 647 | ||
622 | *p++ = '['; | 648 | *p++ = '['; |
623 | num_spec.field_width = size; | 649 | if (res->flags & IORESOURCE_IO) { |
624 | p = number(p, pend, res->start, num_spec); | 650 | p = string(p, pend, "io ", str_spec); |
625 | *p++ = '-'; | 651 | specp = &io_spec; |
626 | p = number(p, pend, res->end, num_spec); | 652 | } else if (res->flags & IORESOURCE_MEM) { |
653 | p = string(p, pend, "mem ", str_spec); | ||
654 | specp = &mem_spec; | ||
655 | } else if (res->flags & IORESOURCE_IRQ) { | ||
656 | p = string(p, pend, "irq ", str_spec); | ||
657 | specp = &dec_spec; | ||
658 | } else if (res->flags & IORESOURCE_DMA) { | ||
659 | p = string(p, pend, "dma ", str_spec); | ||
660 | specp = &dec_spec; | ||
661 | } else if (res->flags & IORESOURCE_BUS) { | ||
662 | p = string(p, pend, "bus ", str_spec); | ||
663 | specp = &bus_spec; | ||
664 | } else { | ||
665 | p = string(p, pend, "??? ", str_spec); | ||
666 | specp = &mem_spec; | ||
667 | decode = 0; | ||
668 | } | ||
669 | p = number(p, pend, res->start, *specp); | ||
670 | if (res->start != res->end) { | ||
671 | *p++ = '-'; | ||
672 | p = number(p, pend, res->end, *specp); | ||
673 | } | ||
674 | if (decode) { | ||
675 | if (res->flags & IORESOURCE_MEM_64) | ||
676 | p = string(p, pend, " 64bit", str_spec); | ||
677 | if (res->flags & IORESOURCE_PREFETCH) | ||
678 | p = string(p, pend, " pref", str_spec); | ||
679 | if (res->flags & IORESOURCE_WINDOW) | ||
680 | p = string(p, pend, " window", str_spec); | ||
681 | if (res->flags & IORESOURCE_DISABLED) | ||
682 | p = string(p, pend, " disabled", str_spec); | ||
683 | } else { | ||
684 | p = string(p, pend, " flags ", str_spec); | ||
685 | p = number(p, pend, res->flags, flag_spec); | ||
686 | } | ||
627 | *p++ = ']'; | 687 | *p++ = ']'; |
628 | *p = 0; | 688 | *p = '\0'; |
629 | 689 | ||
630 | return string(buf, end, sym, spec); | 690 | return string(buf, end, sym, spec); |
631 | } | 691 | } |
@@ -636,24 +696,55 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, | |||
636 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; | 696 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; |
637 | char *p = mac_addr; | 697 | char *p = mac_addr; |
638 | int i; | 698 | int i; |
699 | char separator; | ||
700 | |||
701 | if (fmt[1] == 'F') { /* FDDI canonical format */ | ||
702 | separator = '-'; | ||
703 | } else { | ||
704 | separator = ':'; | ||
705 | } | ||
639 | 706 | ||
640 | for (i = 0; i < 6; i++) { | 707 | for (i = 0; i < 6; i++) { |
641 | p = pack_hex_byte(p, addr[i]); | 708 | p = pack_hex_byte(p, addr[i]); |
642 | if (fmt[0] == 'M' && i != 5) | 709 | if (fmt[0] == 'M' && i != 5) |
643 | *p++ = ':'; | 710 | *p++ = separator; |
644 | } | 711 | } |
645 | *p = '\0'; | 712 | *p = '\0'; |
646 | 713 | ||
647 | return string(buf, end, mac_addr, spec); | 714 | return string(buf, end, mac_addr, spec); |
648 | } | 715 | } |
649 | 716 | ||
650 | static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | 717 | static char *ip4_string(char *p, const u8 *addr, const char *fmt) |
651 | { | 718 | { |
652 | int i; | 719 | int i; |
653 | 720 | bool leading_zeros = (fmt[0] == 'i'); | |
721 | int index; | ||
722 | int step; | ||
723 | |||
724 | switch (fmt[2]) { | ||
725 | case 'h': | ||
726 | #ifdef __BIG_ENDIAN | ||
727 | index = 0; | ||
728 | step = 1; | ||
729 | #else | ||
730 | index = 3; | ||
731 | step = -1; | ||
732 | #endif | ||
733 | break; | ||
734 | case 'l': | ||
735 | index = 3; | ||
736 | step = -1; | ||
737 | break; | ||
738 | case 'n': | ||
739 | case 'b': | ||
740 | default: | ||
741 | index = 0; | ||
742 | step = 1; | ||
743 | break; | ||
744 | } | ||
654 | for (i = 0; i < 4; i++) { | 745 | for (i = 0; i < 4; i++) { |
655 | char temp[3]; /* hold each IP quad in reverse order */ | 746 | char temp[3]; /* hold each IP quad in reverse order */ |
656 | int digits = put_dec_trunc(temp, addr[i]) - temp; | 747 | int digits = put_dec_trunc(temp, addr[index]) - temp; |
657 | if (leading_zeros) { | 748 | if (leading_zeros) { |
658 | if (digits < 3) | 749 | if (digits < 3) |
659 | *p++ = '0'; | 750 | *p++ = '0'; |
@@ -665,23 +756,21 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
665 | *p++ = temp[digits]; | 756 | *p++ = temp[digits]; |
666 | if (i < 3) | 757 | if (i < 3) |
667 | *p++ = '.'; | 758 | *p++ = '.'; |
759 | index += step; | ||
668 | } | 760 | } |
669 | |||
670 | *p = '\0'; | 761 | *p = '\0'; |
762 | |||
671 | return p; | 763 | return p; |
672 | } | 764 | } |
673 | 765 | ||
674 | static char *ip6_compressed_string(char *p, const char *addr) | 766 | static char *ip6_compressed_string(char *p, const char *addr) |
675 | { | 767 | { |
676 | int i; | 768 | int i, j, range; |
677 | int j; | ||
678 | int range; | ||
679 | unsigned char zerolength[8]; | 769 | unsigned char zerolength[8]; |
680 | int longest = 1; | 770 | int longest = 1; |
681 | int colonpos = -1; | 771 | int colonpos = -1; |
682 | u16 word; | 772 | u16 word; |
683 | u8 hi; | 773 | u8 hi, lo; |
684 | u8 lo; | ||
685 | bool needcolon = false; | 774 | bool needcolon = false; |
686 | bool useIPv4; | 775 | bool useIPv4; |
687 | struct in6_addr in6; | 776 | struct in6_addr in6; |
@@ -735,8 +824,9 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
735 | p = pack_hex_byte(p, hi); | 824 | p = pack_hex_byte(p, hi); |
736 | else | 825 | else |
737 | *p++ = hex_asc_lo(hi); | 826 | *p++ = hex_asc_lo(hi); |
827 | p = pack_hex_byte(p, lo); | ||
738 | } | 828 | } |
739 | if (hi || lo > 0x0f) | 829 | else if (lo > 0x0f) |
740 | p = pack_hex_byte(p, lo); | 830 | p = pack_hex_byte(p, lo); |
741 | else | 831 | else |
742 | *p++ = hex_asc_lo(lo); | 832 | *p++ = hex_asc_lo(lo); |
@@ -746,24 +836,25 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
746 | if (useIPv4) { | 836 | if (useIPv4) { |
747 | if (needcolon) | 837 | if (needcolon) |
748 | *p++ = ':'; | 838 | *p++ = ':'; |
749 | p = ip4_string(p, &in6.s6_addr[12], false); | 839 | p = ip4_string(p, &in6.s6_addr[12], "I4"); |
750 | } | 840 | } |
751 | |||
752 | *p = '\0'; | 841 | *p = '\0'; |
842 | |||
753 | return p; | 843 | return p; |
754 | } | 844 | } |
755 | 845 | ||
756 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 846 | static char *ip6_string(char *p, const char *addr, const char *fmt) |
757 | { | 847 | { |
758 | int i; | 848 | int i; |
849 | |||
759 | for (i = 0; i < 8; i++) { | 850 | for (i = 0; i < 8; i++) { |
760 | p = pack_hex_byte(p, *addr++); | 851 | p = pack_hex_byte(p, *addr++); |
761 | p = pack_hex_byte(p, *addr++); | 852 | p = pack_hex_byte(p, *addr++); |
762 | if (fmt[0] == 'I' && i != 7) | 853 | if (fmt[0] == 'I' && i != 7) |
763 | *p++ = ':'; | 854 | *p++ = ':'; |
764 | } | 855 | } |
765 | |||
766 | *p = '\0'; | 856 | *p = '\0'; |
857 | |||
767 | return p; | 858 | return p; |
768 | } | 859 | } |
769 | 860 | ||
@@ -785,11 +876,57 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
785 | { | 876 | { |
786 | char ip4_addr[sizeof("255.255.255.255")]; | 877 | char ip4_addr[sizeof("255.255.255.255")]; |
787 | 878 | ||
788 | ip4_string(ip4_addr, addr, fmt[0] == 'i'); | 879 | ip4_string(ip4_addr, addr, fmt); |
789 | 880 | ||
790 | return string(buf, end, ip4_addr, spec); | 881 | return string(buf, end, ip4_addr, spec); |
791 | } | 882 | } |
792 | 883 | ||
884 | static char *uuid_string(char *buf, char *end, const u8 *addr, | ||
885 | struct printf_spec spec, const char *fmt) | ||
886 | { | ||
887 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | ||
888 | char *p = uuid; | ||
889 | int i; | ||
890 | static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
891 | static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; | ||
892 | const u8 *index = be; | ||
893 | bool uc = false; | ||
894 | |||
895 | switch (*(++fmt)) { | ||
896 | case 'L': | ||
897 | uc = true; /* fall-through */ | ||
898 | case 'l': | ||
899 | index = le; | ||
900 | break; | ||
901 | case 'B': | ||
902 | uc = true; | ||
903 | break; | ||
904 | } | ||
905 | |||
906 | for (i = 0; i < 16; i++) { | ||
907 | p = pack_hex_byte(p, addr[index[i]]); | ||
908 | switch (i) { | ||
909 | case 3: | ||
910 | case 5: | ||
911 | case 7: | ||
912 | case 9: | ||
913 | *p++ = '-'; | ||
914 | break; | ||
915 | } | ||
916 | } | ||
917 | |||
918 | *p = 0; | ||
919 | |||
920 | if (uc) { | ||
921 | p = uuid; | ||
922 | do { | ||
923 | *p = toupper(*p); | ||
924 | } while (*(++p)); | ||
925 | } | ||
926 | |||
927 | return string(buf, end, uuid, spec); | ||
928 | } | ||
929 | |||
793 | /* | 930 | /* |
794 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 931 | * 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 | 932 | * by an extra set of alphanumeric characters that are extended format |
@@ -801,19 +938,34 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
801 | * - 'f' For simple symbolic function names without offset | 938 | * - 'f' For simple symbolic function names without offset |
802 | * - 'S' For symbolic direct pointers with offset | 939 | * - 'S' For symbolic direct pointers with offset |
803 | * - 's' For symbolic direct pointers without offset | 940 | * - 's' For symbolic direct pointers without offset |
804 | * - 'R' For a struct resource pointer, it prints the range of | 941 | * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] |
805 | * addresses (not the name nor the flags) | 942 | * - '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 | 943 | * - 'M' For a 6-byte MAC address, it prints the address in the |
807 | * usual colon-separated hex notation | 944 | * usual colon-separated hex notation |
808 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons | 945 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons |
946 | * - 'MF' For a 6-byte MAC FDDI address, it prints the address | ||
947 | * with a dash-separated hex notation | ||
809 | * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way | 948 | * - '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) | 949 | * 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 | 950 | * IPv6 uses colon separated network-order 16 bit hex with leading 0's |
812 | * - 'i' [46] for 'raw' IPv4/IPv6 addresses | 951 | * - 'i' [46] for 'raw' IPv4/IPv6 addresses |
813 | * IPv6 omits the colons (01020304...0f) | 952 | * IPv6 omits the colons (01020304...0f) |
814 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) | 953 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) |
954 | * - '[Ii]4[hnbl]' IPv4 addresses in host, network, big or little endian order | ||
815 | * - 'I6c' for IPv6 addresses printed as specified by | 955 | * - 'I6c' for IPv6 addresses printed as specified by |
816 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt | 956 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 |
957 | * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form | ||
958 | * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
959 | * Options for %pU are: | ||
960 | * b big endian lower case hex (default) | ||
961 | * B big endian UPPER case hex | ||
962 | * l little endian lower case hex | ||
963 | * L little endian UPPER case hex | ||
964 | * big endian output byte order is: | ||
965 | * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] | ||
966 | * little endian output byte order is: | ||
967 | * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] | ||
968 | * | ||
817 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 969 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
818 | * function pointers are really function descriptors, which contain a | 970 | * function pointers are really function descriptors, which contain a |
819 | * pointer to the real address. | 971 | * pointer to the real address. |
@@ -828,14 +980,16 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
828 | case 'F': | 980 | case 'F': |
829 | case 'f': | 981 | case 'f': |
830 | ptr = dereference_function_descriptor(ptr); | 982 | ptr = dereference_function_descriptor(ptr); |
831 | case 's': | ||
832 | /* Fallthrough */ | 983 | /* Fallthrough */ |
833 | case 'S': | 984 | case 'S': |
985 | case 's': | ||
834 | return symbol_string(buf, end, ptr, spec, *fmt); | 986 | return symbol_string(buf, end, ptr, spec, *fmt); |
835 | case 'R': | 987 | case 'R': |
836 | return resource_string(buf, end, ptr, spec); | 988 | case 'r': |
989 | return resource_string(buf, end, ptr, spec, fmt); | ||
837 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ | 990 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ |
838 | case 'm': /* Contiguous: 000102030405 */ | 991 | case 'm': /* Contiguous: 000102030405 */ |
992 | /* [mM]F (FDDI, bit reversed) */ | ||
839 | return mac_address_string(buf, end, ptr, spec, fmt); | 993 | return mac_address_string(buf, end, ptr, spec, fmt); |
840 | case 'I': /* Formatted IP supported | 994 | case 'I': /* Formatted IP supported |
841 | * 4: 1.2.3.4 | 995 | * 4: 1.2.3.4 |
@@ -853,6 +1007,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
853 | return ip4_addr_string(buf, end, ptr, spec, fmt); | 1007 | return ip4_addr_string(buf, end, ptr, spec, fmt); |
854 | } | 1008 | } |
855 | break; | 1009 | break; |
1010 | case 'U': | ||
1011 | return uuid_string(buf, end, ptr, spec, fmt); | ||
856 | } | 1012 | } |
857 | spec.flags |= SMALL; | 1013 | spec.flags |= SMALL; |
858 | if (spec.field_width == -1) { | 1014 | if (spec.field_width == -1) { |
@@ -970,8 +1126,8 @@ precision: | |||
970 | qualifier: | 1126 | qualifier: |
971 | /* get the conversion qualifier */ | 1127 | /* get the conversion qualifier */ |
972 | spec->qualifier = -1; | 1128 | spec->qualifier = -1; |
973 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1129 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
974 | *fmt == 'Z' || *fmt == 'z' || *fmt == 't') { | 1130 | TOLOWER(*fmt) == 'z' || *fmt == 't') { |
975 | spec->qualifier = *fmt++; | 1131 | spec->qualifier = *fmt++; |
976 | if (unlikely(spec->qualifier == *fmt)) { | 1132 | if (unlikely(spec->qualifier == *fmt)) { |
977 | if (spec->qualifier == 'l') { | 1133 | if (spec->qualifier == 'l') { |
@@ -1038,7 +1194,7 @@ qualifier: | |||
1038 | spec->type = FORMAT_TYPE_LONG; | 1194 | spec->type = FORMAT_TYPE_LONG; |
1039 | else | 1195 | else |
1040 | spec->type = FORMAT_TYPE_ULONG; | 1196 | spec->type = FORMAT_TYPE_ULONG; |
1041 | } else if (spec->qualifier == 'Z' || spec->qualifier == 'z') { | 1197 | } else if (TOLOWER(spec->qualifier) == 'z') { |
1042 | spec->type = FORMAT_TYPE_SIZE_T; | 1198 | spec->type = FORMAT_TYPE_SIZE_T; |
1043 | } else if (spec->qualifier == 't') { | 1199 | } else if (spec->qualifier == 't') { |
1044 | spec->type = FORMAT_TYPE_PTRDIFF; | 1200 | spec->type = FORMAT_TYPE_PTRDIFF; |
@@ -1074,7 +1230,18 @@ qualifier: | |||
1074 | * %ps output the name of a text symbol without offset | 1230 | * %ps output the name of a text symbol without offset |
1075 | * %pF output the name of a function pointer with its offset | 1231 | * %pF output the name of a function pointer with its offset |
1076 | * %pf output the name of a function pointer without its offset | 1232 | * %pf output the name of a function pointer without its offset |
1077 | * %pR output the address range in a struct resource | 1233 | * %pR output the address range in a struct resource with decoded flags |
1234 | * %pr output the address range in a struct resource with raw flags | ||
1235 | * %pM output a 6-byte MAC address with colons | ||
1236 | * %pm output a 6-byte MAC address without colons | ||
1237 | * %pI4 print an IPv4 address without leading zeros | ||
1238 | * %pi4 print an IPv4 address with leading zeros | ||
1239 | * %pI6 print an IPv6 address with colons | ||
1240 | * %pi6 print an IPv6 address without colons | ||
1241 | * %pI6c print an IPv6 address as specified by | ||
1242 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 | ||
1243 | * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper | ||
1244 | * case. | ||
1078 | * %n is ignored | 1245 | * %n is ignored |
1079 | * | 1246 | * |
1080 | * The return value is the number of characters which would | 1247 | * The return value is the number of characters which would |
@@ -1091,8 +1258,7 @@ qualifier: | |||
1091 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | 1258 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
1092 | { | 1259 | { |
1093 | unsigned long long num; | 1260 | unsigned long long num; |
1094 | char *str, *end, c; | 1261 | char *str, *end; |
1095 | int read; | ||
1096 | struct printf_spec spec = {0}; | 1262 | struct printf_spec spec = {0}; |
1097 | 1263 | ||
1098 | /* Reject out-of-range values early. Large positive sizes are | 1264 | /* Reject out-of-range values early. Large positive sizes are |
@@ -1111,8 +1277,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1111 | 1277 | ||
1112 | while (*fmt) { | 1278 | while (*fmt) { |
1113 | const char *old_fmt = fmt; | 1279 | const char *old_fmt = fmt; |
1114 | 1280 | int read = format_decode(fmt, &spec); | |
1115 | read = format_decode(fmt, &spec); | ||
1116 | 1281 | ||
1117 | fmt += read; | 1282 | fmt += read; |
1118 | 1283 | ||
@@ -1136,7 +1301,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1136 | spec.precision = va_arg(args, int); | 1301 | spec.precision = va_arg(args, int); |
1137 | break; | 1302 | break; |
1138 | 1303 | ||
1139 | case FORMAT_TYPE_CHAR: | 1304 | case FORMAT_TYPE_CHAR: { |
1305 | char c; | ||
1306 | |||
1140 | if (!(spec.flags & LEFT)) { | 1307 | if (!(spec.flags & LEFT)) { |
1141 | while (--spec.field_width > 0) { | 1308 | while (--spec.field_width > 0) { |
1142 | if (str < end) | 1309 | if (str < end) |
@@ -1155,6 +1322,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1155 | ++str; | 1322 | ++str; |
1156 | } | 1323 | } |
1157 | break; | 1324 | break; |
1325 | } | ||
1158 | 1326 | ||
1159 | case FORMAT_TYPE_STR: | 1327 | case FORMAT_TYPE_STR: |
1160 | str = string(str, end, va_arg(args, char *), spec); | 1328 | str = string(str, end, va_arg(args, char *), spec); |
@@ -1180,13 +1348,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1180 | break; | 1348 | break; |
1181 | 1349 | ||
1182 | case FORMAT_TYPE_NRCHARS: { | 1350 | case FORMAT_TYPE_NRCHARS: { |
1183 | int qualifier = spec.qualifier; | 1351 | u8 qualifier = spec.qualifier; |
1184 | 1352 | ||
1185 | if (qualifier == 'l') { | 1353 | if (qualifier == 'l') { |
1186 | long *ip = va_arg(args, long *); | 1354 | long *ip = va_arg(args, long *); |
1187 | *ip = (str - buf); | 1355 | *ip = (str - buf); |
1188 | } else if (qualifier == 'Z' || | 1356 | } else if (TOLOWER(qualifier) == 'z') { |
1189 | qualifier == 'z') { | ||
1190 | size_t *ip = va_arg(args, size_t *); | 1357 | size_t *ip = va_arg(args, size_t *); |
1191 | *ip = (str - buf); | 1358 | *ip = (str - buf); |
1192 | } else { | 1359 | } else { |
@@ -1269,7 +1436,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1269 | { | 1436 | { |
1270 | int i; | 1437 | int i; |
1271 | 1438 | ||
1272 | i=vsnprintf(buf,size,fmt,args); | 1439 | i = vsnprintf(buf, size, fmt, args); |
1440 | |||
1273 | return (i >= size) ? (size - 1) : i; | 1441 | return (i >= size) ? (size - 1) : i; |
1274 | } | 1442 | } |
1275 | EXPORT_SYMBOL(vscnprintf); | 1443 | EXPORT_SYMBOL(vscnprintf); |
@@ -1288,14 +1456,15 @@ EXPORT_SYMBOL(vscnprintf); | |||
1288 | * | 1456 | * |
1289 | * See the vsnprintf() documentation for format string extensions over C99. | 1457 | * See the vsnprintf() documentation for format string extensions over C99. |
1290 | */ | 1458 | */ |
1291 | int snprintf(char * buf, size_t size, const char *fmt, ...) | 1459 | int snprintf(char *buf, size_t size, const char *fmt, ...) |
1292 | { | 1460 | { |
1293 | va_list args; | 1461 | va_list args; |
1294 | int i; | 1462 | int i; |
1295 | 1463 | ||
1296 | va_start(args, fmt); | 1464 | va_start(args, fmt); |
1297 | i=vsnprintf(buf,size,fmt,args); | 1465 | i = vsnprintf(buf, size, fmt, args); |
1298 | va_end(args); | 1466 | va_end(args); |
1467 | |||
1299 | return i; | 1468 | return i; |
1300 | } | 1469 | } |
1301 | EXPORT_SYMBOL(snprintf); | 1470 | EXPORT_SYMBOL(snprintf); |
@@ -1311,7 +1480,7 @@ EXPORT_SYMBOL(snprintf); | |||
1311 | * the trailing '\0'. If @size is <= 0 the function returns 0. | 1480 | * the trailing '\0'. If @size is <= 0 the function returns 0. |
1312 | */ | 1481 | */ |
1313 | 1482 | ||
1314 | int scnprintf(char * buf, size_t size, const char *fmt, ...) | 1483 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
1315 | { | 1484 | { |
1316 | va_list args; | 1485 | va_list args; |
1317 | int i; | 1486 | int i; |
@@ -1319,6 +1488,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) | |||
1319 | va_start(args, fmt); | 1488 | va_start(args, fmt); |
1320 | i = vsnprintf(buf, size, fmt, args); | 1489 | i = vsnprintf(buf, size, fmt, args); |
1321 | va_end(args); | 1490 | va_end(args); |
1491 | |||
1322 | return (i >= size) ? (size - 1) : i; | 1492 | return (i >= size) ? (size - 1) : i; |
1323 | } | 1493 | } |
1324 | EXPORT_SYMBOL(scnprintf); | 1494 | EXPORT_SYMBOL(scnprintf); |
@@ -1356,14 +1526,15 @@ EXPORT_SYMBOL(vsprintf); | |||
1356 | * | 1526 | * |
1357 | * See the vsnprintf() documentation for format string extensions over C99. | 1527 | * See the vsnprintf() documentation for format string extensions over C99. |
1358 | */ | 1528 | */ |
1359 | int sprintf(char * buf, const char *fmt, ...) | 1529 | int sprintf(char *buf, const char *fmt, ...) |
1360 | { | 1530 | { |
1361 | va_list args; | 1531 | va_list args; |
1362 | int i; | 1532 | int i; |
1363 | 1533 | ||
1364 | va_start(args, fmt); | 1534 | va_start(args, fmt); |
1365 | i=vsnprintf(buf, INT_MAX, fmt, args); | 1535 | i = vsnprintf(buf, INT_MAX, fmt, args); |
1366 | va_end(args); | 1536 | va_end(args); |
1537 | |||
1367 | return i; | 1538 | return i; |
1368 | } | 1539 | } |
1369 | EXPORT_SYMBOL(sprintf); | 1540 | EXPORT_SYMBOL(sprintf); |
@@ -1396,7 +1567,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args) | |||
1396 | { | 1567 | { |
1397 | struct printf_spec spec = {0}; | 1568 | struct printf_spec spec = {0}; |
1398 | char *str, *end; | 1569 | char *str, *end; |
1399 | int read; | ||
1400 | 1570 | ||
1401 | str = (char *)bin_buf; | 1571 | str = (char *)bin_buf; |
1402 | end = (char *)(bin_buf + size); | 1572 | end = (char *)(bin_buf + size); |
@@ -1421,14 +1591,15 @@ do { \ | |||
1421 | str += sizeof(type); \ | 1591 | str += sizeof(type); \ |
1422 | } while (0) | 1592 | } while (0) |
1423 | 1593 | ||
1424 | |||
1425 | while (*fmt) { | 1594 | while (*fmt) { |
1426 | read = format_decode(fmt, &spec); | 1595 | int read = format_decode(fmt, &spec); |
1427 | 1596 | ||
1428 | fmt += read; | 1597 | fmt += read; |
1429 | 1598 | ||
1430 | switch (spec.type) { | 1599 | switch (spec.type) { |
1431 | case FORMAT_TYPE_NONE: | 1600 | case FORMAT_TYPE_NONE: |
1601 | case FORMAT_TYPE_INVALID: | ||
1602 | case FORMAT_TYPE_PERCENT_CHAR: | ||
1432 | break; | 1603 | break; |
1433 | 1604 | ||
1434 | case FORMAT_TYPE_WIDTH: | 1605 | case FORMAT_TYPE_WIDTH: |
@@ -1443,13 +1614,14 @@ do { \ | |||
1443 | case FORMAT_TYPE_STR: { | 1614 | case FORMAT_TYPE_STR: { |
1444 | const char *save_str = va_arg(args, char *); | 1615 | const char *save_str = va_arg(args, char *); |
1445 | size_t len; | 1616 | size_t len; |
1617 | |||
1446 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE | 1618 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE |
1447 | || (unsigned long)save_str < PAGE_SIZE) | 1619 | || (unsigned long)save_str < PAGE_SIZE) |
1448 | save_str = "<NULL>"; | 1620 | save_str = "(null)"; |
1449 | len = strlen(save_str); | 1621 | len = strlen(save_str) + 1; |
1450 | if (str + len + 1 < end) | 1622 | if (str + len < end) |
1451 | memcpy(str, save_str, len + 1); | 1623 | memcpy(str, save_str, len); |
1452 | str += len + 1; | 1624 | str += len; |
1453 | break; | 1625 | break; |
1454 | } | 1626 | } |
1455 | 1627 | ||
@@ -1460,19 +1632,13 @@ do { \ | |||
1460 | fmt++; | 1632 | fmt++; |
1461 | break; | 1633 | break; |
1462 | 1634 | ||
1463 | case FORMAT_TYPE_PERCENT_CHAR: | ||
1464 | break; | ||
1465 | |||
1466 | case FORMAT_TYPE_INVALID: | ||
1467 | break; | ||
1468 | |||
1469 | case FORMAT_TYPE_NRCHARS: { | 1635 | case FORMAT_TYPE_NRCHARS: { |
1470 | /* skip %n 's argument */ | 1636 | /* skip %n 's argument */ |
1471 | int qualifier = spec.qualifier; | 1637 | u8 qualifier = spec.qualifier; |
1472 | void *skip_arg; | 1638 | void *skip_arg; |
1473 | if (qualifier == 'l') | 1639 | if (qualifier == 'l') |
1474 | skip_arg = va_arg(args, long *); | 1640 | skip_arg = va_arg(args, long *); |
1475 | else if (qualifier == 'Z' || qualifier == 'z') | 1641 | else if (TOLOWER(qualifier) == 'z') |
1476 | skip_arg = va_arg(args, size_t *); | 1642 | skip_arg = va_arg(args, size_t *); |
1477 | else | 1643 | else |
1478 | skip_arg = va_arg(args, int *); | 1644 | skip_arg = va_arg(args, int *); |
@@ -1508,8 +1674,8 @@ do { \ | |||
1508 | } | 1674 | } |
1509 | } | 1675 | } |
1510 | } | 1676 | } |
1511 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1512 | 1677 | ||
1678 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1513 | #undef save_arg | 1679 | #undef save_arg |
1514 | } | 1680 | } |
1515 | EXPORT_SYMBOL_GPL(vbin_printf); | 1681 | EXPORT_SYMBOL_GPL(vbin_printf); |
@@ -1538,11 +1704,9 @@ EXPORT_SYMBOL_GPL(vbin_printf); | |||
1538 | */ | 1704 | */ |
1539 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | 1705 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) |
1540 | { | 1706 | { |
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}; | 1707 | struct printf_spec spec = {0}; |
1708 | char *str, *end; | ||
1709 | const char *args = (const char *)bin_buf; | ||
1546 | 1710 | ||
1547 | if (WARN_ON_ONCE((int) size < 0)) | 1711 | if (WARN_ON_ONCE((int) size < 0)) |
1548 | return 0; | 1712 | return 0; |
@@ -1572,10 +1736,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1572 | } | 1736 | } |
1573 | 1737 | ||
1574 | while (*fmt) { | 1738 | while (*fmt) { |
1575 | int read; | ||
1576 | const char *old_fmt = fmt; | 1739 | const char *old_fmt = fmt; |
1577 | 1740 | int read = format_decode(fmt, &spec); | |
1578 | read = format_decode(fmt, &spec); | ||
1579 | 1741 | ||
1580 | fmt += read; | 1742 | fmt += read; |
1581 | 1743 | ||
@@ -1599,7 +1761,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1599 | spec.precision = get_arg(int); | 1761 | spec.precision = get_arg(int); |
1600 | break; | 1762 | break; |
1601 | 1763 | ||
1602 | case FORMAT_TYPE_CHAR: | 1764 | case FORMAT_TYPE_CHAR: { |
1765 | char c; | ||
1766 | |||
1603 | if (!(spec.flags & LEFT)) { | 1767 | if (!(spec.flags & LEFT)) { |
1604 | while (--spec.field_width > 0) { | 1768 | while (--spec.field_width > 0) { |
1605 | if (str < end) | 1769 | if (str < end) |
@@ -1617,11 +1781,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1617 | ++str; | 1781 | ++str; |
1618 | } | 1782 | } |
1619 | break; | 1783 | break; |
1784 | } | ||
1620 | 1785 | ||
1621 | case FORMAT_TYPE_STR: { | 1786 | case FORMAT_TYPE_STR: { |
1622 | const char *str_arg = args; | 1787 | const char *str_arg = args; |
1623 | size_t len = strlen(str_arg); | 1788 | args += strlen(str_arg) + 1; |
1624 | args += len + 1; | ||
1625 | str = string(str, end, (char *)str_arg, spec); | 1789 | str = string(str, end, (char *)str_arg, spec); |
1626 | break; | 1790 | break; |
1627 | } | 1791 | } |
@@ -1633,11 +1797,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1633 | break; | 1797 | break; |
1634 | 1798 | ||
1635 | case FORMAT_TYPE_PERCENT_CHAR: | 1799 | case FORMAT_TYPE_PERCENT_CHAR: |
1636 | if (str < end) | ||
1637 | *str = '%'; | ||
1638 | ++str; | ||
1639 | break; | ||
1640 | |||
1641 | case FORMAT_TYPE_INVALID: | 1800 | case FORMAT_TYPE_INVALID: |
1642 | if (str < end) | 1801 | if (str < end) |
1643 | *str = '%'; | 1802 | *str = '%'; |
@@ -1648,15 +1807,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1648 | /* skip */ | 1807 | /* skip */ |
1649 | break; | 1808 | break; |
1650 | 1809 | ||
1651 | default: | 1810 | default: { |
1811 | unsigned long long num; | ||
1812 | |||
1652 | switch (spec.type) { | 1813 | switch (spec.type) { |
1653 | 1814 | ||
1654 | case FORMAT_TYPE_LONG_LONG: | 1815 | case FORMAT_TYPE_LONG_LONG: |
1655 | num = get_arg(long long); | 1816 | num = get_arg(long long); |
1656 | break; | 1817 | break; |
1657 | case FORMAT_TYPE_ULONG: | 1818 | case FORMAT_TYPE_ULONG: |
1658 | num = get_arg(unsigned long); | ||
1659 | break; | ||
1660 | case FORMAT_TYPE_LONG: | 1819 | case FORMAT_TYPE_LONG: |
1661 | num = get_arg(unsigned long); | 1820 | num = get_arg(unsigned long); |
1662 | break; | 1821 | break; |
@@ -1686,8 +1845,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1686 | } | 1845 | } |
1687 | 1846 | ||
1688 | str = number(str, end, num, spec); | 1847 | str = number(str, end, num, spec); |
1689 | } | 1848 | } /* default: */ |
1690 | } | 1849 | } /* switch(spec.type) */ |
1850 | } /* while(*fmt) */ | ||
1691 | 1851 | ||
1692 | if (size > 0) { | 1852 | if (size > 0) { |
1693 | if (str < end) | 1853 | if (str < end) |
@@ -1721,6 +1881,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) | |||
1721 | va_start(args, fmt); | 1881 | va_start(args, fmt); |
1722 | ret = vbin_printf(bin_buf, size, fmt, args); | 1882 | ret = vbin_printf(bin_buf, size, fmt, args); |
1723 | va_end(args); | 1883 | va_end(args); |
1884 | |||
1724 | return ret; | 1885 | return ret; |
1725 | } | 1886 | } |
1726 | EXPORT_SYMBOL_GPL(bprintf); | 1887 | EXPORT_SYMBOL_GPL(bprintf); |
@@ -1733,27 +1894,25 @@ EXPORT_SYMBOL_GPL(bprintf); | |||
1733 | * @fmt: format of buffer | 1894 | * @fmt: format of buffer |
1734 | * @args: arguments | 1895 | * @args: arguments |
1735 | */ | 1896 | */ |
1736 | int vsscanf(const char * buf, const char * fmt, va_list args) | 1897 | int vsscanf(const char *buf, const char *fmt, va_list args) |
1737 | { | 1898 | { |
1738 | const char *str = buf; | 1899 | const char *str = buf; |
1739 | char *next; | 1900 | char *next; |
1740 | char digit; | 1901 | char digit; |
1741 | int num = 0; | 1902 | int num = 0; |
1742 | int qualifier; | 1903 | u8 qualifier; |
1743 | int base; | 1904 | u8 base; |
1744 | int field_width; | 1905 | s16 field_width; |
1745 | int is_sign = 0; | 1906 | bool is_sign; |
1746 | 1907 | ||
1747 | while(*fmt && *str) { | 1908 | while (*fmt && *str) { |
1748 | /* skip any white space in format */ | 1909 | /* skip any white space in format */ |
1749 | /* white space in format matchs any amount of | 1910 | /* white space in format matchs any amount of |
1750 | * white space, including none, in the input. | 1911 | * white space, including none, in the input. |
1751 | */ | 1912 | */ |
1752 | if (isspace(*fmt)) { | 1913 | if (isspace(*fmt)) { |
1753 | while (isspace(*fmt)) | 1914 | fmt = skip_spaces(++fmt); |
1754 | ++fmt; | 1915 | str = skip_spaces(str); |
1755 | while (isspace(*str)) | ||
1756 | ++str; | ||
1757 | } | 1916 | } |
1758 | 1917 | ||
1759 | /* anything that is not a conversion must match exactly */ | 1918 | /* anything that is not a conversion must match exactly */ |
@@ -1766,7 +1925,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1766 | if (!*fmt) | 1925 | if (!*fmt) |
1767 | break; | 1926 | break; |
1768 | ++fmt; | 1927 | ++fmt; |
1769 | 1928 | ||
1770 | /* skip this conversion. | 1929 | /* skip this conversion. |
1771 | * advance both strings to next white space | 1930 | * advance both strings to next white space |
1772 | */ | 1931 | */ |
@@ -1785,8 +1944,8 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1785 | 1944 | ||
1786 | /* get conversion qualifier */ | 1945 | /* get conversion qualifier */ |
1787 | qualifier = -1; | 1946 | qualifier = -1; |
1788 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1947 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
1789 | *fmt == 'Z' || *fmt == 'z') { | 1948 | TOLOWER(*fmt) == 'z') { |
1790 | qualifier = *fmt++; | 1949 | qualifier = *fmt++; |
1791 | if (unlikely(qualifier == *fmt)) { | 1950 | if (unlikely(qualifier == *fmt)) { |
1792 | if (qualifier == 'h') { | 1951 | if (qualifier == 'h') { |
@@ -1798,16 +1957,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1798 | } | 1957 | } |
1799 | } | 1958 | } |
1800 | } | 1959 | } |
1801 | base = 10; | ||
1802 | is_sign = 0; | ||
1803 | 1960 | ||
1804 | if (!*fmt || !*str) | 1961 | if (!*fmt || !*str) |
1805 | break; | 1962 | break; |
1806 | 1963 | ||
1807 | switch(*fmt++) { | 1964 | base = 10; |
1965 | is_sign = 0; | ||
1966 | |||
1967 | switch (*fmt++) { | ||
1808 | case 'c': | 1968 | case 'c': |
1809 | { | 1969 | { |
1810 | char *s = (char *) va_arg(args,char*); | 1970 | char *s = (char *)va_arg(args, char*); |
1811 | if (field_width == -1) | 1971 | if (field_width == -1) |
1812 | field_width = 1; | 1972 | field_width = 1; |
1813 | do { | 1973 | do { |
@@ -1818,17 +1978,15 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1818 | continue; | 1978 | continue; |
1819 | case 's': | 1979 | case 's': |
1820 | { | 1980 | { |
1821 | char *s = (char *) va_arg(args, char *); | 1981 | char *s = (char *)va_arg(args, char *); |
1822 | if(field_width == -1) | 1982 | if (field_width == -1) |
1823 | field_width = INT_MAX; | 1983 | field_width = SHORT_MAX; |
1824 | /* first, skip leading white space in buffer */ | 1984 | /* first, skip leading white space in buffer */ |
1825 | while (isspace(*str)) | 1985 | str = skip_spaces(str); |
1826 | str++; | ||
1827 | 1986 | ||
1828 | /* now copy until next white space */ | 1987 | /* now copy until next white space */ |
1829 | while (*str && !isspace(*str) && field_width--) { | 1988 | while (*str && !isspace(*str) && field_width--) |
1830 | *s++ = *str++; | 1989 | *s++ = *str++; |
1831 | } | ||
1832 | *s = '\0'; | 1990 | *s = '\0'; |
1833 | num++; | 1991 | num++; |
1834 | } | 1992 | } |
@@ -1836,7 +1994,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1836 | case 'n': | 1994 | case 'n': |
1837 | /* return number of characters read so far */ | 1995 | /* return number of characters read so far */ |
1838 | { | 1996 | { |
1839 | int *i = (int *)va_arg(args,int*); | 1997 | int *i = (int *)va_arg(args, int*); |
1840 | *i = str - buf; | 1998 | *i = str - buf; |
1841 | } | 1999 | } |
1842 | continue; | 2000 | continue; |
@@ -1848,14 +2006,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1848 | base = 16; | 2006 | base = 16; |
1849 | break; | 2007 | break; |
1850 | case 'i': | 2008 | case 'i': |
1851 | base = 0; | 2009 | base = 0; |
1852 | case 'd': | 2010 | case 'd': |
1853 | is_sign = 1; | 2011 | is_sign = 1; |
1854 | case 'u': | 2012 | case 'u': |
1855 | break; | 2013 | break; |
1856 | case '%': | 2014 | case '%': |
1857 | /* looking for '%' in str */ | 2015 | /* looking for '%' in str */ |
1858 | if (*str++ != '%') | 2016 | if (*str++ != '%') |
1859 | return num; | 2017 | return num; |
1860 | continue; | 2018 | continue; |
1861 | default: | 2019 | default: |
@@ -1866,71 +2024,70 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1866 | /* have some sort of integer conversion. | 2024 | /* have some sort of integer conversion. |
1867 | * first, skip white space in buffer. | 2025 | * first, skip white space in buffer. |
1868 | */ | 2026 | */ |
1869 | while (isspace(*str)) | 2027 | str = skip_spaces(str); |
1870 | str++; | ||
1871 | 2028 | ||
1872 | digit = *str; | 2029 | digit = *str; |
1873 | if (is_sign && digit == '-') | 2030 | if (is_sign && digit == '-') |
1874 | digit = *(str + 1); | 2031 | digit = *(str + 1); |
1875 | 2032 | ||
1876 | if (!digit | 2033 | if (!digit |
1877 | || (base == 16 && !isxdigit(digit)) | 2034 | || (base == 16 && !isxdigit(digit)) |
1878 | || (base == 10 && !isdigit(digit)) | 2035 | || (base == 10 && !isdigit(digit)) |
1879 | || (base == 8 && (!isdigit(digit) || digit > '7')) | 2036 | || (base == 8 && (!isdigit(digit) || digit > '7')) |
1880 | || (base == 0 && !isdigit(digit))) | 2037 | || (base == 0 && !isdigit(digit))) |
1881 | break; | 2038 | break; |
1882 | 2039 | ||
1883 | switch(qualifier) { | 2040 | switch (qualifier) { |
1884 | case 'H': /* that's 'hh' in format */ | 2041 | case 'H': /* that's 'hh' in format */ |
1885 | if (is_sign) { | 2042 | if (is_sign) { |
1886 | signed char *s = (signed char *) va_arg(args,signed char *); | 2043 | signed char *s = (signed char *)va_arg(args, signed char *); |
1887 | *s = (signed char) simple_strtol(str,&next,base); | 2044 | *s = (signed char)simple_strtol(str, &next, base); |
1888 | } else { | 2045 | } else { |
1889 | unsigned char *s = (unsigned char *) va_arg(args, unsigned char *); | 2046 | unsigned char *s = (unsigned char *)va_arg(args, unsigned char *); |
1890 | *s = (unsigned char) simple_strtoul(str, &next, base); | 2047 | *s = (unsigned char)simple_strtoul(str, &next, base); |
1891 | } | 2048 | } |
1892 | break; | 2049 | break; |
1893 | case 'h': | 2050 | case 'h': |
1894 | if (is_sign) { | 2051 | if (is_sign) { |
1895 | short *s = (short *) va_arg(args,short *); | 2052 | short *s = (short *)va_arg(args, short *); |
1896 | *s = (short) simple_strtol(str,&next,base); | 2053 | *s = (short)simple_strtol(str, &next, base); |
1897 | } else { | 2054 | } else { |
1898 | unsigned short *s = (unsigned short *) va_arg(args, unsigned short *); | 2055 | unsigned short *s = (unsigned short *)va_arg(args, unsigned short *); |
1899 | *s = (unsigned short) simple_strtoul(str, &next, base); | 2056 | *s = (unsigned short)simple_strtoul(str, &next, base); |
1900 | } | 2057 | } |
1901 | break; | 2058 | break; |
1902 | case 'l': | 2059 | case 'l': |
1903 | if (is_sign) { | 2060 | if (is_sign) { |
1904 | long *l = (long *) va_arg(args,long *); | 2061 | long *l = (long *)va_arg(args, long *); |
1905 | *l = simple_strtol(str,&next,base); | 2062 | *l = simple_strtol(str, &next, base); |
1906 | } else { | 2063 | } else { |
1907 | unsigned long *l = (unsigned long*) va_arg(args,unsigned long*); | 2064 | unsigned long *l = (unsigned long *)va_arg(args, unsigned long *); |
1908 | *l = simple_strtoul(str,&next,base); | 2065 | *l = simple_strtoul(str, &next, base); |
1909 | } | 2066 | } |
1910 | break; | 2067 | break; |
1911 | case 'L': | 2068 | case 'L': |
1912 | if (is_sign) { | 2069 | if (is_sign) { |
1913 | long long *l = (long long*) va_arg(args,long long *); | 2070 | long long *l = (long long *)va_arg(args, long long *); |
1914 | *l = simple_strtoll(str,&next,base); | 2071 | *l = simple_strtoll(str, &next, base); |
1915 | } else { | 2072 | } else { |
1916 | unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*); | 2073 | unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *); |
1917 | *l = simple_strtoull(str,&next,base); | 2074 | *l = simple_strtoull(str, &next, base); |
1918 | } | 2075 | } |
1919 | break; | 2076 | break; |
1920 | case 'Z': | 2077 | case 'Z': |
1921 | case 'z': | 2078 | case 'z': |
1922 | { | 2079 | { |
1923 | size_t *s = (size_t*) va_arg(args,size_t*); | 2080 | size_t *s = (size_t *)va_arg(args, size_t *); |
1924 | *s = (size_t) simple_strtoul(str,&next,base); | 2081 | *s = (size_t)simple_strtoul(str, &next, base); |
1925 | } | 2082 | } |
1926 | break; | 2083 | break; |
1927 | default: | 2084 | default: |
1928 | if (is_sign) { | 2085 | if (is_sign) { |
1929 | int *i = (int *) va_arg(args, int*); | 2086 | int *i = (int *)va_arg(args, int *); |
1930 | *i = (int) simple_strtol(str,&next,base); | 2087 | *i = (int)simple_strtol(str, &next, base); |
1931 | } else { | 2088 | } else { |
1932 | unsigned int *i = (unsigned int*) va_arg(args, unsigned int*); | 2089 | unsigned int *i = (unsigned int *)va_arg(args, unsigned int*); |
1933 | *i = (unsigned int) simple_strtoul(str,&next,base); | 2090 | *i = (unsigned int)simple_strtoul(str, &next, base); |
1934 | } | 2091 | } |
1935 | break; | 2092 | break; |
1936 | } | 2093 | } |
@@ -1961,14 +2118,15 @@ EXPORT_SYMBOL(vsscanf); | |||
1961 | * @fmt: formatting of buffer | 2118 | * @fmt: formatting of buffer |
1962 | * @...: resulting arguments | 2119 | * @...: resulting arguments |
1963 | */ | 2120 | */ |
1964 | int sscanf(const char * buf, const char * fmt, ...) | 2121 | int sscanf(const char *buf, const char *fmt, ...) |
1965 | { | 2122 | { |
1966 | va_list args; | 2123 | va_list args; |
1967 | int i; | 2124 | int i; |
1968 | 2125 | ||
1969 | va_start(args,fmt); | 2126 | va_start(args, fmt); |
1970 | i = vsscanf(buf,fmt,args); | 2127 | i = vsscanf(buf, fmt, args); |
1971 | va_end(args); | 2128 | va_end(args); |
2129 | |||
1972 | return i; | 2130 | return i; |
1973 | } | 2131 | } |
1974 | EXPORT_SYMBOL(sscanf); | 2132 | EXPORT_SYMBOL(sscanf); |