diff --git a/bionic.c b/bionic.c index e42092a..93e6c57 100644 --- a/bionic.c +++ b/bionic.c @@ -288,396 +288,6 @@ int _toupper(char c) return c + ('a' - 'A'); } -static int get_cuts(int base, unsigned long *cutoff, int *cutlim) -{ - switch(base) { - case 1: - *cutoff = 4294967295; - *cutlim = 0; - break; - - case 2: - *cutoff = 2147483647; - *cutlim = 1; - break; - - case 3: - *cutoff = 1431655765; - *cutlim = 0; - break; - - case 4: - *cutoff = 1073741823; - *cutlim = 3; - break; - - case 5: - *cutoff = 858993459; - *cutlim = 0; - break; - - case 6: - *cutoff = 715827882; - *cutlim = 3; - break; - - case 7: - *cutoff = 613566756; - *cutlim = 3; - break; - - case 8: - *cutoff = 536870911; - *cutlim = 7; - break; - - case 9: - *cutoff = 477218588; - *cutlim = 3; - break; - - case 10: - *cutoff = 429496729; - *cutlim = 5; - break; - - case 11: - *cutoff = 390451572; - *cutlim = 3; - break; - - case 12: - *cutoff = 357913941; - *cutlim = 3; - break; - - case 13: - *cutoff = 330382099; - *cutlim = 8; - break; - - case 14: - *cutoff = 306783378; - *cutlim = 3; - break; - - case 15: - *cutoff = 286331153; - *cutlim = 0; - break; - - case 16: - *cutoff = 268435455; - *cutlim = 15; - break; - - case 17: - *cutoff = 252645135; - *cutlim = 0; - break; - - case 18: - *cutoff = 238609294; - *cutlim = 3; - break; - - case 19: - *cutoff = 226050910; - *cutlim = 5; - break; - - case 20: - *cutoff = 214748364; - *cutlim = 15; - break; - - case 21: - *cutoff = 204522252; - *cutlim = 3; - break; - - case 22: - *cutoff = 195225786; - *cutlim = 3; - break; - - case 23: - *cutoff = 186737708; - *cutlim = 11; - break; - - case 24: - *cutoff = 178956970; - *cutlim = 15; - break; - - case 25: - *cutoff = 171798691; - *cutlim = 20; - break; - - case 26: - *cutoff = 165191049; - *cutlim = 21; - break; - - case 27: - *cutoff = 159072862; - *cutlim = 21; - break; - - case 28: - *cutoff = 153391689; - *cutlim = 3; - break; - - case 29: - *cutoff = 148102320; - *cutlim = 15; - break; - - case 30: - *cutoff = 143165576; - *cutlim = 15; - break; - - case 31: - *cutoff = 138547332; - *cutlim = 3; - break; - - case 32: - *cutoff = 134217727; - *cutlim = 31; - break; - - case 33: - *cutoff = 130150524; - *cutlim = 3; - break; - - case 34: - *cutoff = 126322567; - *cutlim = 17; - break; - - case 35: - *cutoff = 122713351; - *cutlim = 10; - break; - - case 36: - *cutoff = 119304647; - *cutlim = 3; - break; - - case 37: - *cutoff = 116080197; - *cutlim = 6; - break; - - case 38: - *cutoff = 113025455; - *cutlim = 5; - break; - - case 39: - *cutoff = 110127366; - *cutlim = 21; - break; - - case 40: - *cutoff = 107374182; - *cutlim = 15; - break; - - case 41: - *cutoff = 104755299; - *cutlim = 36; - break; - - case 42: - *cutoff = 102261126; - *cutlim = 3; - break; - - case 43: - *cutoff = 99882960; - *cutlim = 15; - break; - - case 44: - *cutoff = 97612893; - *cutlim = 3; - break; - - case 45: - *cutoff = 95443717; - *cutlim = 30; - break; - - case 46: - *cutoff = 93368854; - *cutlim = 11; - break; - - case 47: - *cutoff = 91382282; - *cutlim = 41; - break; - - case 48: - *cutoff = 89478485; - *cutlim = 15; - break; - - case 49: - *cutoff = 87652393; - *cutlim = 38; - break; - - case 50: - *cutoff = 85899345; - *cutlim = 45; - break; - - case 51: - *cutoff = 84215045; - *cutlim = 0; - break; - - case 52: - *cutoff = 82595524; - *cutlim = 47; - break; - - case 53: - *cutoff = 81037118; - *cutlim = 41; - break; - - case 54: - *cutoff = 79536431; - *cutlim = 21; - break; - - case 55: - *cutoff = 78090314; - *cutlim = 25; - break; - - case 56: - *cutoff = 76695844; - *cutlim = 31; - break; - - case 57: - *cutoff = 75350303; - *cutlim = 24; - break; - - case 58: - *cutoff = 74051160; - *cutlim = 15; - break; - - case 59: - *cutoff = 72796055; - *cutlim = 50; - break; - - case 60: - *cutoff = 71582788; - *cutlim = 15; - break; - - case 61: - *cutoff = 70409299; - *cutlim = 56; - break; - - case 62: - *cutoff = 69273666; - *cutlim = 3; - break; - - case 63: - *cutoff = 68174084; - *cutlim = 3; - break; - - case 64: - *cutoff = 67108863; - *cutlim = 63; - break; - - default: - break; - } - - return 0; -} - -unsigned long _strtoul(const void *nptr, void **endptr, int base) -{ - const char *s; - unsigned long acc, cutoff; - int c; - int neg, any, cutlim; - - /* - * See strtol for comments as to the logic used. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (_isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - get_cuts(base, &cutoff, &cutlim); - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (_isdigit(c)) - c -= '0'; - else if (_isalpha(c)) - c -= _isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = ULONG_MAX; - //errno = ERANGE; - } else { - any = 1; - acc *= (unsigned long)base; - acc += c; - } - } - if (neg && any > 0) - acc = -acc; - if (endptr != 0) - *(char **)endptr = (char *) (any ? s - 1 : nptr); - return (acc); -} - void _memset(void *dst0, char val, size_t length) { uint8_t *ptr = dst0; diff --git a/include/bionic.h b/include/bionic.h index cbceeb4..83eead6 100644 --- a/include/bionic.h +++ b/include/bionic.h @@ -10,7 +10,7 @@ char *_strtok(char *str, const char *delim, char **saveptr); int _strcasecmp(const char *s1, const char *s2); void *_memcpy(void *dst0, const void *src0, size_t length); void _memset(void *dst0, char val, size_t length); -unsigned long _strtoul(const void *nptr, void **endptr, int base); +unsigned long strtoul(const char *nptr, char **endptr, unsigned int base); int _strlen(const char *s); int _strnlen(const char *s, uint32_t maxlen); void _usleep(uint32_t usecs);