From c46b3f6d965d45d69d4287f8935e0540f7fa0417 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Fri, 28 Jun 2019 15:28:36 +0800 Subject: [PATCH] lib: add stdlib.c Since we need to realize standard library function other than use them with gcc tool chain in U-Boot. So add standard library function here. Change-Id: I10009c5bbe31fabacd929df3c44218ae9c6a885f Signed-off-by: Jason Zhu --- include/stdlib.h | 2 ++ lib/Makefile | 1 + lib/stdlib.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 lib/stdlib.c 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); +}