Add atoi to stdlib
This commit is contained in:
parent
2718379e6d
commit
fa2c3487af
@ -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__ */
|
||||
|
||||
|
@ -18,6 +18,7 @@ src_common = [
|
||||
"process.c",
|
||||
"posix/mman.c",
|
||||
"posix/pthread.c",
|
||||
"stdlib.c",
|
||||
"string.c",
|
||||
"syscall.c",
|
||||
"time.c",
|
||||
|
18
lib/libc/stdlib.c
Normal file
18
lib/libc/stdlib.c
Normal file
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user