diff --git a/include/stdlib.h b/include/stdlib.h index 6bc7fbb3c4..5b87ea0237 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -9,4 +9,6 @@ #include +int atoi(const char *nptr); + #endif /* __STDLIB_H_ */ diff --git a/lib/Makefile b/lib/Makefile index 30f195b66f..d62b97caf0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -90,6 +90,7 @@ obj-y += linux_string.o obj-y += membuff.o obj-$(CONFIG_REGEX) += slre.o obj-y += string.o +obj-y += stdlib.o obj-y += tables_csum.o obj-y += time.o obj-$(CONFIG_TRACE) += trace.o diff --git a/lib/stdlib.c b/lib/stdlib.c new file mode 100644 index 0000000000..e4f15f91a3 --- /dev/null +++ b/lib/stdlib.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd + */ + +#include +#include + +long atol(const char *nptr) +{ + int c; + long total; + int sign; + + while (isspace((int)(unsigned char)*nptr)) + ++nptr; + + c = (int)(unsigned char)*nptr++; + sign = c; + if (c == '-' || c == '+') + c = (int)(unsigned char)*nptr++; + + total = 0; + + while (isdigit(c)) { + total = 10 * total + (c - '0'); + c = (int)(unsigned char)*nptr++; + } + + if (sign == '-') + return -total; + else + return total; +} + +int atoi(const char *nptr) +{ + return (int)atol(nptr); +}