From 4546c75d685475d8b9f215b588364e1d1bbd0b79 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 29 Apr 2020 19:21:29 +0200 Subject: MUCH work in libc Also cleaned up some syscalls etc --- src/userspace/libc/stdlib/htoi.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/userspace/libc/stdlib/htoi.c (limited to 'src/userspace/libc/stdlib/htoi.c') diff --git a/src/userspace/libc/stdlib/htoi.c b/src/userspace/libc/stdlib/htoi.c new file mode 100644 index 0000000..cf79b7a --- /dev/null +++ b/src/userspace/libc/stdlib/htoi.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int htoi(char *str) +{ + u8 s_str = strlen(str); + + u8 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, (int)((s_str - i) - 1)); + } + + return ret; +} \ No newline at end of file -- cgit v1.2.3