Hi,
perhaps this is known, but it struck me as odd:
when the string given to strtonum() correspomnds
is a valid numeric string, but the value is too small,
the error msg pointed to by strtonum will be "too small",
but the message corresponding to errno = ERANGE will be
"Result too large" (because that's ERANGE). Example below.
There is hardly any better errno to be set of course,
but calling err() after a failed strtonum() might print
a message that is a bit confusing.
Jan
$ cat num.c
#include <stdlib.h>
#include <err.h>
int
main(int argc, char** argv)
{
long long n = 0;
const char *e = NULL;
if (argc != 2)
return 1;
n = strtonum(argv[1], 2, 5, &e);
if ((n == 0) && (e))
err(1, "%s %s", argv[1], e);
return 0;
}
$ make num
`num' is up to date.
$ ./num 6
num: 6 too large: Result too large
$ ./num 5
$ ./num 2
$ ./num 1
num: 1 too small: Result too large
$ ./num 0
num: 0 too small: Result too large
$ ./num -1
num: -1 too small: Result too large
$ ./num -2
num: -2 too small: Result too large