opuntiaOS - an operating system targeting x86 and ARMv7
at master 334 B view raw
1#include <stdlib.h> 2#include <string.h> 3 4int atoi(const char* s) 5{ 6 // FIXME: Add overflow checks 7 int res = 0; 8 int len = strlen(s); 9 int mul = 1; 10 for (int i = 0; i < len; i++) { 11 mul *= 10; 12 } 13 for (int i = 0; i < len; i++) { 14 mul /= 10; 15 res += (s[i] - '0') * mul; 16 } 17 return res; 18}