summaryrefslogtreecommitdiffstats
path: root/libc/bionic
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-04-22 17:56:42 -0700
committerElliott Hughes <enh@google.com>2014-04-22 17:56:42 -0700
commiteae5902e73dc4381811e08fd2334bf4a9300a928 (patch)
tree2ba628d1e74d046bd87ec060a68d0cc6d7b52100 /libc/bionic
parent635edbdf93a127da7db77d9cd174615734b4fb85 (diff)
downloadbionic-eae5902e73dc4381811e08fd2334bf4a9300a928.zip
bionic-eae5902e73dc4381811e08fd2334bf4a9300a928.tar.gz
bionic-eae5902e73dc4381811e08fd2334bf4a9300a928.tar.bz2
Remove strntoimax and strntoumax from the future.
Where do these turds come from? Change-Id: Id9ad2cc85c6128aa63b5d56ff2aa455bde39a5eb
Diffstat (limited to 'libc/bionic')
-rw-r--r--libc/bionic/ndk_cruft.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 7826651..2fed492 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -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