sbase/util/estrtol.c

23 lines
405 B
C
Raw Normal View History

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