xref: /OK3568_Linux_fs/u-boot/lib/stdlib.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd
4  */
5 
6 #include <linux/ctype.h>
7 #include <linux/types.h>
8 
atol(const char * nptr)9 long atol(const char *nptr)
10 {
11 	int c;
12 	long total;
13 	int sign;
14 
15 	while (isspace((int)(unsigned char)*nptr))
16 		++nptr;
17 
18 	c = (int)(unsigned char)*nptr++;
19 	sign = c;
20 	if (c == '-' || c == '+')
21 		c = (int)(unsigned char)*nptr++;
22 
23 	total = 0;
24 
25 	while (isdigit(c)) {
26 		total = 10 * total + (c - '0');
27 		c = (int)(unsigned char)*nptr++;
28 	}
29 
30 	if (sign == '-')
31 		return -total;
32 	else
33 		return total;
34 }
35 
atoi(const char * nptr)36 int atoi(const char *nptr)
37 {
38 	return (int)atol(nptr);
39 }
40