Rev 8793 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9765 | turbocat | 1 | #include |
8687 | turbocat | 2 | #include |
3 | |||
9765 | turbocat | 4 | long atol(const char* s) |
8687 | turbocat | 5 | { |
9765 | turbocat | 6 | long n = 0; |
7 | int neg = 0; |
||
8 | while (isspace(*s)) |
||
9 | s++; |
||
10 | switch (*s) { |
||
11 | case '-': |
||
12 | neg = 1; |
||
13 | case '+': |
||
14 | s++; |
||
15 | } |
||
16 | /* Compute n as a negative number to avoid overflow on LONG_MIN */ |
||
17 | while (isdigit(*s)) |
||
18 | n = 10 * n - (*s++ - '0'); |
||
19 | return neg ? n : -n; |
||
8687 | turbocat | 20 | } |