I want a function that will interpret a string as a strictly unsigned integer, failing when the string overflows, represents a negative number, or does not represent a number.
strtoull()
does set errno to ERANGE on overflow or EINVAL for a string that does not begin with a number, but accepts negative numbers as valid.
strtoumax()
is the same as strtoull()
atoll()
and strtonum()
are ruled out because they are strictly for signed integers.
sscanf()
sets errno to ERANGE on overflow and stops processing the string if it does not begin with a number (reflected in sscanf's return value), but also accepts negative numbers as valid.
Is there another option that I'm missing?
-
in the input then use somestrtoull