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 <jason.zhu@rock-chips.com>
This commit is contained in:
Jason Zhu 2019-06-28 15:28:36 +08:00 committed by Jianhong Chen
parent d6d708d1a3
commit c46b3f6d96
3 changed files with 42 additions and 0 deletions

View File

@ -9,4 +9,6 @@
#include <malloc.h>
int atoi(const char *nptr);
#endif /* __STDLIB_H_ */

View File

@ -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

39
lib/stdlib.c Normal file
View File

@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd
*/
#include <linux/ctype.h>
#include <linux/types.h>
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);
}