Add estrtoul()
This commit is contained in:
parent
e077e0c00a
commit
b90ca482a0
1
Makefile
1
Makefile
@ -40,6 +40,7 @@ LIBUTILSRC =\
|
||||
libutil/eregcomp.c\
|
||||
libutil/estrtod.c\
|
||||
libutil/estrtol.c\
|
||||
libutil/estrtoul.c\
|
||||
libutil/fnck.c\
|
||||
libutil/getlines.c\
|
||||
libutil/human.c\
|
||||
|
26
libutil/estrtoul.c
Normal file
26
libutil/estrtoul.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../util.h"
|
||||
|
||||
unsigned long
|
||||
estrtoul(const char *s, int base)
|
||||
{
|
||||
char *end;
|
||||
unsigned long n;
|
||||
|
||||
errno = 0;
|
||||
n = strtoul(s, &end, base);
|
||||
if (*end != '\0') {
|
||||
if (base == 0)
|
||||
eprintf("%s: not an integer\n", s);
|
||||
else
|
||||
eprintf("%s: not a base %d integer\n", s, base);
|
||||
}
|
||||
if (errno != 0)
|
||||
eprintf("%s:", s);
|
||||
|
||||
return n;
|
||||
}
|
Loading…
Reference in New Issue
Block a user