Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / stdlib / atol.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: atol.c,v 1.5 1994/06/24 11:53:23 ceriel Exp $ */
6
7 #include        <ctype.h>
8
9 /* We do not use strtol here for backwards compatibility in behaviour on
10    overflow.
11 */
12 long
13 atol(register const char *nptr)
14 {
15         long total = 0;
16         int minus = 0;
17
18         while (isspace(*nptr)) nptr++;
19         if (*nptr == '+') nptr++;
20         else if (*nptr == '-') {
21                 minus = 1;
22                 nptr++;
23         }
24         while (isdigit(*nptr)) {
25                 total *= 10;
26                 total += (*nptr++ - '0');
27         }
28         return minus ? -total : total;
29 }