Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/xatonum_template.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/xatonum_template.c
r1765 r2725 1 /* 2 * 3 * Licensed under GPLv2, see file LICENSE in this source tree. 4 */ 1 5 /* 2 6 You need to define the following (example): … … 13 17 */ 14 18 15 unsigned type xstrtou(_range_sfx)(const char *numstr, int base,19 unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base, 16 20 unsigned type lower, 17 21 unsigned type upper, … … 22 26 char *e; 23 27 24 /* Disallow '-' and any leading whitespace. Speed isn't critical here 25 * since we're parsing commandline args. So make sure we get the 26 * actual isspace function rather than a lnumstrer macro implementaion. */ 27 if (*numstr == '-' || *numstr == '+' || (isspace)(*numstr)) 28 /* Disallow '-' and any leading whitespace. */ 29 if (*numstr == '-' || *numstr == '+' || isspace(*numstr)) 28 30 goto inval; 29 31 … … 40 42 goto inval; /* error / no digits / illegal trailing chars */ 41 43 42 errno = old_errno; 44 errno = old_errno; /* Ok. So restore errno. */ 43 45 44 46 /* Do optional suffix parsing. Allow 'empty' suffix tables. … … 73 75 } 74 76 75 unsigned type xstrtou(_range)(const char *numstr, int base,77 unsigned type FAST_FUNC xstrtou(_range)(const char *numstr, int base, 76 78 unsigned type lower, 77 79 unsigned type upper) … … 80 82 } 81 83 82 unsigned type xstrtou(_sfx)(const char *numstr, int base,84 unsigned type FAST_FUNC xstrtou(_sfx)(const char *numstr, int base, 83 85 const struct suffix_mult *suffixes) 84 86 { … … 86 88 } 87 89 88 unsigned type xstrtou()(const char *numstr, int base)90 unsigned type FAST_FUNC xstrtou()(const char *numstr, int base) 89 91 { 90 92 return xstrtou(_range_sfx)(numstr, base, 0, XSTR_UTYPE_MAX, NULL); 91 93 } 92 94 93 unsigned type xatou(_range_sfx)(const char *numstr,95 unsigned type FAST_FUNC xatou(_range_sfx)(const char *numstr, 94 96 unsigned type lower, 95 97 unsigned type upper, … … 99 101 } 100 102 101 unsigned type xatou(_range)(const char *numstr,103 unsigned type FAST_FUNC xatou(_range)(const char *numstr, 102 104 unsigned type lower, 103 105 unsigned type upper) … … 106 108 } 107 109 108 unsigned type xatou(_sfx)(const char *numstr,110 unsigned type FAST_FUNC xatou(_sfx)(const char *numstr, 109 111 const struct suffix_mult *suffixes) 110 112 { … … 112 114 } 113 115 114 unsigned type xatou()(const char *numstr)116 unsigned type FAST_FUNC xatou()(const char *numstr) 115 117 { 116 118 return xatou(_sfx)(numstr, NULL); … … 119 121 /* Signed ones */ 120 122 121 type xstrto(_range_sfx)(const char *numstr, int base,123 type FAST_FUNC xstrto(_range_sfx)(const char *numstr, int base, 122 124 type lower, 123 125 type upper, … … 128 130 const char *p = numstr; 129 131 130 if (p[0] == '-') { 132 /* NB: if you'll decide to disallow '+': 133 * at least renice applet needs to allow it */ 134 if (p[0] == '+' || p[0] == '-') { 131 135 ++p; 132 ++u; /* two's complement */ 136 if (p[0] == '-') 137 ++u; /* = <type>_MIN (01111... + 1 == 10000...) */ 133 138 } 134 139 … … 147 152 } 148 153 149 type xstrto(_range)(const char *numstr, int base, type lower, type upper)154 type FAST_FUNC xstrto(_range)(const char *numstr, int base, type lower, type upper) 150 155 { 151 156 return xstrto(_range_sfx)(numstr, base, lower, upper, NULL); 152 157 } 153 158 154 type xato(_range_sfx)(const char *numstr, 159 type FAST_FUNC xstrto()(const char *numstr, int base) 160 { 161 return xstrto(_range_sfx)(numstr, base, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL); 162 } 163 164 type FAST_FUNC xato(_range_sfx)(const char *numstr, 155 165 type lower, 156 166 type upper, … … 160 170 } 161 171 162 type xato(_range)(const char *numstr, type lower, type upper)172 type FAST_FUNC xato(_range)(const char *numstr, type lower, type upper) 163 173 { 164 174 return xstrto(_range_sfx)(numstr, 10, lower, upper, NULL); 165 175 } 166 176 167 type xato(_sfx)(const char *numstr, const struct suffix_mult *suffixes)177 type FAST_FUNC xato(_sfx)(const char *numstr, const struct suffix_mult *suffixes) 168 178 { 169 179 return xstrto(_range_sfx)(numstr, 10, XSTR_TYPE_MIN, XSTR_TYPE_MAX, suffixes); 170 180 } 171 181 172 type xato()(const char *numstr)182 type FAST_FUNC xato()(const char *numstr) 173 183 { 174 184 return xstrto(_range_sfx)(numstr, 10, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.