xref: /minix3/minix/lib/libminc/atoi.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* Extracted from sys/arch/i386/stand/lib/bootmenu.c */
2*433d6423SLionel Sambuc int atoi(const char *);
3*433d6423SLionel Sambuc 
4*433d6423SLionel Sambuc #define isnum(c) ((c) >= '0' && (c) <= '9')
5*433d6423SLionel Sambuc 
6*433d6423SLionel Sambuc int
atoi(const char * in)7*433d6423SLionel Sambuc atoi(const char *in)
8*433d6423SLionel Sambuc {
9*433d6423SLionel Sambuc 	const char *c;
10*433d6423SLionel Sambuc 	int ret;
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc 	ret = 0;
13*433d6423SLionel Sambuc 	c = in;
14*433d6423SLionel Sambuc 	if (*c == '-')
15*433d6423SLionel Sambuc 		c++;
16*433d6423SLionel Sambuc 	for (; isnum(*c); c++)
17*433d6423SLionel Sambuc 		ret = (ret * 10) + (*c - '0');
18*433d6423SLionel Sambuc 
19*433d6423SLionel Sambuc 	return (*in == '-') ? -ret : ret;
20*433d6423SLionel Sambuc }
21*433d6423SLionel Sambuc 
22