From d94b024b73aeca06de417e0fd3c502495312a8b2 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 7 Dec 2019 13:40:28 +0100 Subject: Added userspace libc and began userspace based shell --- src/kernel/lib/stdlib/atoi.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/kernel/lib/stdlib/atoi.c (limited to 'src/kernel/lib/stdlib/atoi.c') diff --git a/src/kernel/lib/stdlib/atoi.c b/src/kernel/lib/stdlib/atoi.c new file mode 100644 index 0000000..4044972 --- /dev/null +++ b/src/kernel/lib/stdlib/atoi.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int atoi(char *str) +{ + size_t s_str = strlen(str); + if (!s_str) return 0; + + uint8_t negative = 0; + if (str[0] == '-') negative = 1; + + size_t i = 0; + if (negative) i++; + + int ret = 0; + for (; i < s_str; i++) { + ret += (str[i] - '0') * pow(10, (s_str - i) - 1); + } + + if (negative) ret *= -1; + return ret; +} \ No newline at end of file -- cgit v1.2.3