blob: 6d3d4cceb6683214cfe51807116051a365098c60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <lib.h>
#define ATOX(name, type) \
type name(const char *s) \
{ \
for (; isspace(*s); s++) \
; \
int neg = 0; \
switch (*s) { \
case '-': \
neg = 1; \
/* fallthrough */ \
case '+': \
s++; \
break; \
} \
type num = 0; \
for (; *s == '0'; s++) \
; \
for (; isdigit(*s); s++) { \
num *= 10; \
num += *s - '0'; \
} \
return num * (neg ? -1 : 1); \
}
ATOX(atoi, int)
ATOX(atol, long int)
ATOX(atoll, long long int)
|