diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-04-16 16:55:24 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-04-16 16:55:24 -0400 |
commit | 96e9773eb764afa649b099a6e283dba4c69389a9 (patch) | |
tree | 52e2223324cce3db02ff6318ad3f8eb940bd8d5f /src/internal | |
parent | 18efeb320b763e541a7dbf61a7da1cbe13ab2be9 (diff) | |
download | musl-96e9773eb764afa649b099a6e283dba4c69389a9.tar.gz musl-96e9773eb764afa649b099a6e283dba4c69389a9.tar.bz2 musl-96e9773eb764afa649b099a6e283dba4c69389a9.tar.xz musl-96e9773eb764afa649b099a6e283dba4c69389a9.zip |
use the new integer parser (FILE/shgetc based) for strtol, wcstol, etc.
Diffstat (limited to 'src/internal')
-rw-r--r-- | src/internal/intparse.c | 116 | ||||
-rw-r--r-- | src/internal/intparse.h | 11 |
2 files changed, 0 insertions, 127 deletions
diff --git a/src/internal/intparse.c b/src/internal/intparse.c deleted file mode 100644 index fba38c0a..00000000 --- a/src/internal/intparse.c +++ /dev/null @@ -1,116 +0,0 @@ -#include <stdint.h> -#include <limits.h> -#include <stdlib.h> -#include <errno.h> -#include "intparse.h" - -/* Lookup table for digit values. -1==255>=36 -> invalid */ -static const unsigned char digits[] = { --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -}; - -#define SLIM (UINT_MAX/36-1) - -int __intparse(struct intparse *v, const void *buf, size_t n) -{ - const unsigned char *s = buf; - int d, b = v->base; - uintmax_t llim; - - v->cnt += n; - for (; n; n--, s++) switch (v->state) { - case 0: - v->err = EINVAL; - v->state++; - if (*s=='+' || *s=='-') { - v->neg = *s=='-'; - continue; - } - case 1: - v->state++; - if (*s=='0' && (!b || b==16)) continue; - if (!b) v->base = b = 10; - v->state++; - goto firstdigit; - case 2: - v->state++; - if ((!b || b==16) && (*s|32) == 'x') { - v->err = 0; - v->base = b = 16; - continue; - } - if (!b) v->base = b = 8; - goto seconddigit; - case 3: - firstdigit: - if (digits[*s] >= b) { - n++; - goto finished; - } - seconddigit: - v->err = 0; - v->state++; - case 4: - if (b==10) { - for (; n && *s-'0'<10U && v->small<=SLIM; n--, s++) - v->small = v->small * 10 + (*s-'0'); - } else if ((b&-b) == b) { - /* Compute bitshift for power-of-two bases - * using a De Bruijn B(2,3) sequence. */ - int bs = "\0\1\2\4\7\3\6\5"[(0x17*b)>>5&7]; - for (; n && (d=digits[*s])<b && v->small<=SLIM; n--, s++) - v->small = (v->small<<bs) + d; - } else { - for (; n && (d=digits[*s])<b && v->small<=SLIM; n--, s++) - v->small = v->small * b + d; - } - if (!n) return 1; - v->state++; - v->val = v->small; - case 5: - if (b==10) { - for (; n && *s-'0'<10U && v->val<=UINTMAX_MAX/10 && (*s-'0')<=UINTMAX_MAX-10*v->val; n--, s++) - v->val = v->val * 10 + (*s-'0'); - } else if ((b&-b) == b) { - int bs = "\0\1\2\4\7\3\6\5"[(0x17*b)>>5&7]; - llim = UINTMAX_MAX>>bs; - for (; n && (d=digits[*s])<b && v->val<=llim; n--, s++) - v->val = (v->val<<bs) + d; - } else { - llim = UINTMAX_MAX/b; - for (; n && (d=digits[*s])<b && v->val<=llim && d<=UINTMAX_MAX-b*v->val; n--, s++) - v->val = v->val * b + d; - } - if (!n) return 1; - if (d >= b) goto finished; - v->state++; - case 6: - if (n && digits[*s]<b) { - v->err = ERANGE; - v->val = UINTMAX_MAX; - n--; s++; - for (; n && digits[*s]<b; n--, s++); - } - if (!n) return 1; - goto finished; - } - return 1; -finished: - v->cnt -= n; - return 0; -} diff --git a/src/internal/intparse.h b/src/internal/intparse.h deleted file mode 100644 index 78e800d1..00000000 --- a/src/internal/intparse.h +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdint.h> -#include <stddef.h> - -struct intparse { - uintmax_t val; - unsigned small; - size_t cnt; - char neg, base, state, err; -}; - -int __intparse(struct intparse *, const void *, size_t); |