12 if (*s
== '-' || *s
== '+')
14 while ((unsigned) (*s
- '0') <= 9u)
15 num
= num
* 10 + *s
++ - '0';
16 return neg
? -num
: num
;
25 if (*s
== '-' || *s
== '+')
27 while ((unsigned) (*s
- '0') <= 9u)
28 num
= num
* 10 + *s
++ - '0';
29 return neg
? -num
: num
;
32 static int digit(char c
, int base
)
37 } else if (c
<= 'Z') {
42 return d
< base
? d
: -1;
45 long strtol(const char *s
, char **endptr
, int base
)
53 if (*s
== '-' || *s
== '+')
57 if (s
[1] == 'x' || s
[1] == 'X')
65 if (base
== 16 && *s
== '0' && (s
[1] == 'x' || s
[1] == 'X'))
67 for (num
= 0; (dig
= digit(*s
, base
)) >= 0; s
++) {
68 if (num
> LONG_MAX
/ base
)
71 if (num
> LONG_MAX
- dig
)
78 num
= sgn
> 0 ? LONG_MAX
: LONG_MIN
;
86 unsigned long strtoul(const char *s
, char **endptr
, int base
)
94 if (*s
== '-' || *s
== '+')
98 if (s
[1] == 'x' || s
[1] == 'X')
106 if (base
== 16 && *s
== '0' && (s
[1] == 'x' || s
[1] == 'X'))
108 for (num
= 0; (dig
= digit(*s
, base
)) >= 0; s
++) {
109 if (num
> (unsigned long) ULONG_MAX
/ base
)
112 if (num
> (unsigned long) ULONG_MAX
- dig
)