2021-04-27 18:33:31 +02:00
|
|
|
#include <ctype.h>
|
2022-04-15 11:00:55 +02:00
|
|
|
#include <stdlib.h>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
long atol(const char* s)
|
2021-04-27 18:33:31 +02:00
|
|
|
{
|
2022-04-15 11:00:55 +02:00
|
|
|
long n = 0;
|
|
|
|
int neg = 0;
|
|
|
|
while (isspace(*s))
|
|
|
|
s++;
|
|
|
|
switch (*s) {
|
|
|
|
case '-':
|
|
|
|
neg = 1;
|
|
|
|
case '+':
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
/* Compute n as a negative number to avoid overflow on LONG_MIN */
|
|
|
|
while (isdigit(*s))
|
|
|
|
n = 10 * n - (*s++ - '0');
|
|
|
|
return neg ? n : -n;
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|