aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c47
1 files changed, 14 insertions, 33 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d7222a9c8267..993599e66e5a 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -31,17 +31,7 @@
31#include <asm/div64.h> 31#include <asm/div64.h>
32#include <asm/sections.h> /* for dereference_function_descriptor() */ 32#include <asm/sections.h> /* for dereference_function_descriptor() */
33 33
34static unsigned int simple_guess_base(const char *cp) 34#include "kstrtox.h"
35{
36 if (cp[0] == '0') {
37 if (_tolower(cp[1]) == 'x' && isxdigit(cp[2]))
38 return 16;
39 else
40 return 8;
41 } else {
42 return 10;
43 }
44}
45 35
46/** 36/**
47 * simple_strtoull - convert a string to an unsigned long long 37 * simple_strtoull - convert a string to an unsigned long long
@@ -51,23 +41,14 @@ static unsigned int simple_guess_base(const char *cp)
51 */ 41 */
52unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) 42unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
53{ 43{
54 unsigned long long result = 0; 44 unsigned long long result;
45 unsigned int rv;
55 46
56 if (!base) 47 cp = _parse_integer_fixup_radix(cp, &base);
57 base = simple_guess_base(cp); 48 rv = _parse_integer(cp, base, &result);
49 /* FIXME */
50 cp += (rv & ~KSTRTOX_OVERFLOW);
58 51
59 if (base == 16 && cp[0] == '0' && _tolower(cp[1]) == 'x')
60 cp += 2;
61
62 while (isxdigit(*cp)) {
63 unsigned int value;
64
65 value = isdigit(*cp) ? *cp - '0' : _tolower(*cp) - 'a' + 10;
66 if (value >= base)
67 break;
68 result = result * base + value;
69 cp++;
70 }
71 if (endp) 52 if (endp)
72 *endp = (char *)cp; 53 *endp = (char *)cp;
73 54
@@ -566,7 +547,7 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
566 } 547 }
567 548
568 for (i = 0; i < 6; i++) { 549 for (i = 0; i < 6; i++) {
569 p = pack_hex_byte(p, addr[i]); 550 p = hex_byte_pack(p, addr[i]);
570 if (fmt[0] == 'M' && i != 5) 551 if (fmt[0] == 'M' && i != 5)
571 *p++ = separator; 552 *p++ = separator;
572 } 553 }
@@ -686,13 +667,13 @@ char *ip6_compressed_string(char *p, const char *addr)
686 lo = word & 0xff; 667 lo = word & 0xff;
687 if (hi) { 668 if (hi) {
688 if (hi > 0x0f) 669 if (hi > 0x0f)
689 p = pack_hex_byte(p, hi); 670 p = hex_byte_pack(p, hi);
690 else 671 else
691 *p++ = hex_asc_lo(hi); 672 *p++ = hex_asc_lo(hi);
692 p = pack_hex_byte(p, lo); 673 p = hex_byte_pack(p, lo);
693 } 674 }
694 else if (lo > 0x0f) 675 else if (lo > 0x0f)
695 p = pack_hex_byte(p, lo); 676 p = hex_byte_pack(p, lo);
696 else 677 else
697 *p++ = hex_asc_lo(lo); 678 *p++ = hex_asc_lo(lo);
698 needcolon = true; 679 needcolon = true;
@@ -714,8 +695,8 @@ char *ip6_string(char *p, const char *addr, const char *fmt)
714 int i; 695 int i;
715 696
716 for (i = 0; i < 8; i++) { 697 for (i = 0; i < 8; i++) {
717 p = pack_hex_byte(p, *addr++); 698 p = hex_byte_pack(p, *addr++);
718 p = pack_hex_byte(p, *addr++); 699 p = hex_byte_pack(p, *addr++);
719 if (fmt[0] == 'I' && i != 7) 700 if (fmt[0] == 'I' && i != 7)
720 *p++ = ':'; 701 *p++ = ':';
721 } 702 }
@@ -773,7 +754,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
773 } 754 }
774 755
775 for (i = 0; i < 16; i++) { 756 for (i = 0; i < 16; i++) {
776 p = pack_hex_byte(p, addr[index[i]]); 757 p = hex_byte_pack(p, addr[index[i]]);
777 switch (i) { 758 switch (i) {
778 case 3: 759 case 3:
779 case 5: 760 case 5: