aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Geiselbrecht <geist@foobox.com>2013-07-31 11:14:08 -0700
committerTravis Geiselbrecht <geist@foobox.com>2013-07-31 11:14:08 -0700
commit9d9067f8817eb8621d6689fb4aa2091c83f6c4c0 (patch)
treefa5e66c037f239ac86abb783082575d340800d01
parent71d36e61184b2ce24ce6ec699c16a2d770612f62 (diff)
downloadlk-9d9067f8817eb8621d6689fb4aa2091c83f6c4c0.tar.gz
[libc] add implementation of atoull
-rw-r--r--include/stdlib.h1
-rw-r--r--lib/libc/atoi.c18
2 files changed, 19 insertions, 0 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index c31dd9c1..a602ccb2 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -34,6 +34,7 @@ int atoi(const char *num);
unsigned int atoui(const char *num);
long atol(const char *num);
unsigned long atoul(const char *num);
+unsigned long long atoull(const char *num);
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
diff --git a/lib/libc/atoi.c b/lib/libc/atoi.c
index 809e1830..f5610835 100644
--- a/lib/libc/atoi.c
+++ b/lib/libc/atoi.c
@@ -103,3 +103,21 @@ unsigned long atoul(const char *num)
return value;
}
+unsigned long long atoull(const char *num)
+{
+ unsigned long long value = 0;
+ if (num[0] == '0' && num[1] == 'x') {
+ // hex
+ num += 2;
+ while (*num && isxdigit(*num))
+ value = value * 16 + hexval(*num++);
+ } else {
+ // decimal
+ while (*num && isdigit(*num))
+ value = value * 10 + *num++ - '0';
+ }
+
+ return value;
+}
+
+