xref: /csrg-svn/lib/libc/stdlib/atol.c (revision 35103)
1*35103Sbostic /*
2*35103Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*35103Sbostic  * All rights reserved.
4*35103Sbostic  *
5*35103Sbostic  * Redistribution and use in source and binary forms are permitted
6*35103Sbostic  * provided that the above copyright notice and this paragraph are
7*35103Sbostic  * duplicated in all such forms and that any documentation,
8*35103Sbostic  * advertising materials, and other materials related to such
9*35103Sbostic  * distribution and use acknowledge that the software was developed
10*35103Sbostic  * by the University of California, Berkeley.  The name of the
11*35103Sbostic  * University may not be used to endorse or promote products derived
12*35103Sbostic  * from this software without specific prior written permission.
13*35103Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*35103Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*35103Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16*35103Sbostic  */
17*35103Sbostic 
1826543Sdonn #if defined(LIBC_SCCS) && !defined(lint)
19*35103Sbostic static char sccsid[] = "@(#)atol.c	5.3 (Berkeley) 07/19/88";
20*35103Sbostic #endif /* LIBC_SCCS and not lint */
2122081Smckusick 
22*35103Sbostic #include <ctype.h>
23*35103Sbostic 
241955Swnj long
25*35103Sbostic atol(ascii)
26*35103Sbostic 	register char *ascii;
271955Swnj {
28*35103Sbostic 	register long val;
29*35103Sbostic 	int negative = 0;
301955Swnj 
31*35103Sbostic 	for (; isascii(*ascii) && isspace(*ascii); ++ascii);
32*35103Sbostic 	if (*ascii == '+')
33*35103Sbostic 		++ascii;
34*35103Sbostic 	else if (*ascii == '-') {
35*35103Sbostic 		++ascii;
36*35103Sbostic 		negative = 1;
371955Swnj 	}
38*35103Sbostic 	for (val = 0; isascii(*ascii) && isdigit(*ascii); ++ascii)
39*35103Sbostic 		val = val * 10 + *ascii - '0';
40*35103Sbostic 	return(negative ? -val : val);
411955Swnj }
42