diff --git a/include/stdlib.h b/include/stdlib.h index 877b74d..a5fe2ad 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -16,5 +16,7 @@ void *calloc(size_t num, size_t sz); void *malloc(size_t sz); void free(void *buf); +int atoi(const char *nptr); + #endif /* __STDLIB_H__ */ diff --git a/lib/libc/SConscript b/lib/libc/SConscript index d8e511c..f8aa670 100644 --- a/lib/libc/SConscript +++ b/lib/libc/SConscript @@ -18,6 +18,7 @@ src_common = [ "process.c", "posix/mman.c", "posix/pthread.c", + "stdlib.c", "string.c", "syscall.c", "time.c", diff --git a/lib/libc/stdlib.c b/lib/libc/stdlib.c new file mode 100644 index 0000000..19c4d12 --- /dev/null +++ b/lib/libc/stdlib.c @@ -0,0 +1,18 @@ + +int +atoi(const char *nptr) +{ + int i = 0; + int val = 0; + + while (nptr[i] != '\0') { + if (nptr[i] >= '0' && nptr[i] <= '9') { + val = val * 10 + (int)(nptr[i] - '0'); + } else { + return 0; + } + } + + return val; +} +