2011-06-10 00:46:20 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2012-05-20 08:51:18 -04:00
|
|
|
#include <errno.h>
|
2011-06-10 00:46:20 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2011-06-10 00:46:20 -04:00
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
long
|
2011-06-10 09:55:01 -04:00
|
|
|
estrtol(const char *s, int base)
|
2011-06-10 00:46:20 -04:00
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
long n;
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2012-05-20 08:51:18 -04:00
|
|
|
errno = 0;
|
2011-06-10 00:46:20 -04:00
|
|
|
n = strtol(s, &end, base);
|
2012-05-20 08:51:18 -04:00
|
|
|
if(*end != '\0' || errno != 0) {
|
2013-03-05 15:46:48 -05:00
|
|
|
if(base == 0) {
|
2012-05-10 14:20:16 -04:00
|
|
|
eprintf("%s: not an integer\n", s);
|
2013-03-05 15:46:48 -05:00
|
|
|
} else {
|
2012-05-10 14:20:16 -04:00
|
|
|
eprintf("%s: not a base %d integer\n", s, base);
|
2013-03-05 15:46:48 -05:00
|
|
|
}
|
2011-06-10 00:46:20 -04:00
|
|
|
}
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2011-06-10 00:46:20 -04:00
|
|
|
return n;
|
|
|
|
}
|
2013-03-05 15:46:48 -05:00
|
|
|
|