vsprintf.c (20036fdcaf05fac0a84ed81a56906493a7d822e2) | vsprintf.c (aa46a63efc896f0a6d54e7614e750788793582e5) |
---|---|
1/* 2 * linux/lib/vsprintf.c 3 * 4 * Copyright (C) 1991, 1992 Linus Torvalds 5 */ 6 7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ 8/* --- 18 unchanged lines hidden (view full) --- 27 28#include <asm/page.h> /* for PAGE_SIZE */ 29#include <asm/div64.h> 30#include <asm/sections.h> /* for dereference_function_descriptor() */ 31 32/* Works only for digits and letters, but small and fast */ 33#define TOLOWER(x) ((x) | 0x20) 34 | 1/* 2 * linux/lib/vsprintf.c 3 * 4 * Copyright (C) 1991, 1992 Linus Torvalds 5 */ 6 7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ 8/* --- 18 unchanged lines hidden (view full) --- 27 28#include <asm/page.h> /* for PAGE_SIZE */ 29#include <asm/div64.h> 30#include <asm/sections.h> /* for dereference_function_descriptor() */ 31 32/* Works only for digits and letters, but small and fast */ 33#define TOLOWER(x) ((x) | 0x20) 34 |
35static unsigned int simple_guess_base(const char *cp) 36{ 37 if (cp[0] == '0') { 38 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2])) 39 return 16; 40 else 41 return 8; 42 } else { 43 return 10; 44 } 45} 46 |
|
35/** 36 * simple_strtoul - convert a string to an unsigned long 37 * @cp: The start of the string 38 * @endp: A pointer to the end of the parsed string will be placed here 39 * @base: The number base to use 40 */ 41unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) 42{ | 47/** 48 * simple_strtoul - convert a string to an unsigned long 49 * @cp: The start of the string 50 * @endp: A pointer to the end of the parsed string will be placed here 51 * @base: The number base to use 52 */ 53unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) 54{ |
43 unsigned long result = 0,value; | 55 unsigned long result = 0; |
44 | 56 |
45 if (!base) { 46 base = 10; 47 if (*cp == '0') { 48 base = 8; 49 cp++; 50 if ((TOLOWER(*cp) == 'x') && isxdigit(cp[1])) { 51 cp++; 52 base = 16; 53 } 54 } 55 } else if (base == 16) { 56 if (cp[0] == '0' && TOLOWER(cp[1]) == 'x') 57 cp += 2; 58 } 59 while (isxdigit(*cp) && 60 (value = isdigit(*cp) ? *cp-'0' : TOLOWER(*cp)-'a'+10) < base) { 61 result = result*base + value; | 57 if (!base) 58 base = simple_guess_base(cp); 59 60 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') 61 cp += 2; 62 63 while (isxdigit(*cp)) { 64 unsigned int value; 65 66 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; 67 if (value >= base) 68 break; 69 result = result * base + value; |
62 cp++; 63 } | 70 cp++; 71 } |
72 |
|
64 if (endp) 65 *endp = (char *)cp; 66 return result; 67} | 73 if (endp) 74 *endp = (char *)cp; 75 return result; 76} |
68 | |
69EXPORT_SYMBOL(simple_strtoul); 70 71/** 72 * simple_strtol - convert a string to a signed long 73 * @cp: The start of the string 74 * @endp: A pointer to the end of the parsed string will be placed here 75 * @base: The number base to use 76 */ --- 9 unchanged lines hidden (view full) --- 86/** 87 * simple_strtoull - convert a string to an unsigned long long 88 * @cp: The start of the string 89 * @endp: A pointer to the end of the parsed string will be placed here 90 * @base: The number base to use 91 */ 92unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) 93{ | 77EXPORT_SYMBOL(simple_strtoul); 78 79/** 80 * simple_strtol - convert a string to a signed long 81 * @cp: The start of the string 82 * @endp: A pointer to the end of the parsed string will be placed here 83 * @base: The number base to use 84 */ --- 9 unchanged lines hidden (view full) --- 94/** 95 * simple_strtoull - convert a string to an unsigned long long 96 * @cp: The start of the string 97 * @endp: A pointer to the end of the parsed string will be placed here 98 * @base: The number base to use 99 */ 100unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) 101{ |
94 unsigned long long result = 0,value; | 102 unsigned long long result = 0; |
95 | 103 |
96 if (!base) { 97 base = 10; 98 if (*cp == '0') { 99 base = 8; 100 cp++; 101 if ((TOLOWER(*cp) == 'x') && isxdigit(cp[1])) { 102 cp++; 103 base = 16; 104 } 105 } 106 } else if (base == 16) { 107 if (cp[0] == '0' && TOLOWER(cp[1]) == 'x') 108 cp += 2; 109 } 110 while (isxdigit(*cp) 111 && (value = isdigit(*cp) ? *cp-'0' : TOLOWER(*cp)-'a'+10) < base) { 112 result = result*base + value; | 104 if (!base) 105 base = simple_guess_base(cp); 106 107 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') 108 cp += 2; 109 110 while (isxdigit(*cp)) { 111 unsigned int value; 112 113 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; 114 if (value >= base) 115 break; 116 result = result * base + value; |
113 cp++; 114 } | 117 cp++; 118 } |
119 |
|
115 if (endp) 116 *endp = (char *)cp; 117 return result; 118} | 120 if (endp) 121 *endp = (char *)cp; 122 return result; 123} |
119 | |
120EXPORT_SYMBOL(simple_strtoull); 121 122/** 123 * simple_strtoll - convert a string to a signed long long 124 * @cp: The start of the string 125 * @endp: A pointer to the end of the parsed string will be placed here 126 * @base: The number base to use 127 */ --- 1042 unchanged lines hidden --- | 124EXPORT_SYMBOL(simple_strtoull); 125 126/** 127 * simple_strtoll - convert a string to a signed long long 128 * @cp: The start of the string 129 * @endp: A pointer to the end of the parsed string will be placed here 130 * @base: The number base to use 131 */ --- 1042 unchanged lines hidden --- |