diff options
author | Marvin Borner | 2020-04-29 19:21:29 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-29 19:21:29 +0200 |
commit | 4546c75d685475d8b9f215b588364e1d1bbd0b79 (patch) | |
tree | 2077f72ad46dfe877f7febdd0692edc139fd7937 /src/userspace/libc/stdlib/atoi.c | |
parent | 396d7d303d3bf0e796d0c817883ec1dec928352a (diff) |
MUCH work in libc
Also cleaned up some syscalls etc
Diffstat (limited to 'src/userspace/libc/stdlib/atoi.c')
-rw-r--r-- | src/userspace/libc/stdlib/atoi.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/userspace/libc/stdlib/atoi.c b/src/userspace/libc/stdlib/atoi.c new file mode 100644 index 0000000..21b6c25 --- /dev/null +++ b/src/userspace/libc/stdlib/atoi.c @@ -0,0 +1,28 @@ +#include <stddef.h> +#include <stdint.h> +#include <string.h> +#include <math.h> + +int atoi(char *str) +{ + u8 s_str = strlen(str); + if (!s_str) + return 0; + + u8 negative = 0; + if (str[0] == '-') + negative = 1; + + u8 i = 0; + if (negative) + i++; + + int ret = 0; + for (; i < s_str; i++) { + ret += (str[i] - '0') * pow(10, (int)((s_str - i) - 1)); + } + + if (negative) + ret *= -1; + return ret; +}
\ No newline at end of file |