whoops, add strnum.c
This commit is contained in:
parent
ba456787cb
commit
afb1f0ead0
20
util/strnum.c
Normal file
20
util/strnum.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
long
|
||||||
|
strnum(const char *s, int base)
|
||||||
|
{
|
||||||
|
char *end;
|
||||||
|
long n;
|
||||||
|
|
||||||
|
n = strtol(s, &end, base);
|
||||||
|
if(*end != '\0') {
|
||||||
|
if(base == 0)
|
||||||
|
eprintf("%s: not a number\n", s);
|
||||||
|
else
|
||||||
|
eprintf("%s: not a base %d number\n", s, base);
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user