aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/stdlib/htoi.c
diff options
context:
space:
mode:
authorMarvin Borner2019-12-07 13:40:28 +0100
committerMarvin Borner2019-12-07 13:40:28 +0100
commitd94b024b73aeca06de417e0fd3c502495312a8b2 (patch)
treebff5cc1b757eeed7f58878cc13551c63464c5a31 /src/kernel/lib/stdlib/htoi.c
parent322167ceab19588473f9074e761390fdeb701790 (diff)
Added userspace libc and began userspace based shell
Diffstat (limited to 'src/kernel/lib/stdlib/htoi.c')
-rw-r--r--src/kernel/lib/stdlib/htoi.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/kernel/lib/stdlib/htoi.c b/src/kernel/lib/stdlib/htoi.c
new file mode 100644
index 0000000..f2d4702
--- /dev/null
+++ b/src/kernel/lib/stdlib/htoi.c
@@ -0,0 +1,23 @@
+#include <kernel/lib/math.h>
+#include <stddef.h>
+#include <kernel/lib/string.h>
+
+int htoi(char *str)
+{
+ size_t s_str = strlen(str);
+
+ size_t i = 0;
+ int ret = 0;
+ for (; i < s_str; i++) {
+ char c = str[i];
+ int aux = 0;
+ if (c >= '0' && c <= '9')
+ aux = c - '0';
+ else if (c >= 'A' && c <= 'F')
+ aux = (c - 'A') + 10;
+
+ ret += aux * pow(16, (s_str - i) - 1);
+ }
+
+ return ret;
+} \ No newline at end of file