Merge "Remove strntoimax and strntoumax from the future."

This commit is contained in:
Elliott Hughes 2014-04-23 01:50:08 +00:00 committed by Gerrit Code Review
commit d8f8e9c59e
3 changed files with 68 additions and 5 deletions

View File

@ -69,8 +69,6 @@ libc_common_src_files := \
bionic/sigblock.c \
bionic/siginterrupt.c \
bionic/sigsetmask.c \
bionic/strntoimax.c \
bionic/strntoumax.c \
bionic/system_properties_compat.c \
bionic/unlockpt.c \
stdio/findfp.c \

View File

@ -116,4 +116,72 @@ extern "C" char* strtotimeval(const char* str, struct timeval* ts) {
return s;
}
static inline int digitval(int ch) {
unsigned d;
d = (unsigned)(ch - '0');
if (d < 10) return (int)d;
d = (unsigned)(ch - 'a');
if (d < 6) return (int)(d+10);
d = (unsigned)(ch - 'A');
if (d < 6) return (int)(d+10);
return -1;
}
// This non-standard function was in our <inttypes.h> for some reason.
extern "C" uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) {
const unsigned char* p = (const unsigned char *)nptr;
const unsigned char* end = p + n;
int minus = 0;
uintmax_t v = 0;
int d;
while (p < end && isspace(*p)) {
p++;
}
if (p < end) {
char c = p[0];
if (c == '-' || c == '+') {
minus = (c == '-');
p++;
}
}
if (base == 0) {
if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
p += 2;
base = 16;
} else if (p+1 < end && p[0] == '0') {
p += 1;
base = 8;
} else {
base = 10;
}
} else if (base == 16) {
if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
p += 2;
}
}
while (p < end && (d = digitval(*p)) >= 0 && d < base) {
v = v*base + d;
p += 1;
}
if (endptr) {
*endptr = (char*) p;
}
return minus ? -v : v;
}
// This non-standard function was in our <inttypes.h> for some reason.
extern "C" intmax_t strntoimax(const char* nptr, char** endptr, int base, size_t n) {
return (intmax_t) strntoumax(nptr, endptr, base, n);
}
#endif

View File

@ -261,9 +261,6 @@ imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2;
intmax_t strtoimax(const char *, char **, int);
uintmax_t strtoumax(const char *, char **, int);
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n);
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n);
__END_DECLS
#endif /* _INTTYPES_H_ */