lib/atoi/: a2i(): Re-implement with a statement expression
Synopsis
int a2i(typename T, T *restrict n, QChar *s,
QChar **_Nullable restrict endp, int base,
T min, T max);
Description
This macro converts the initial portion of the string pointed to
by 's' to an integer of base 'base', ensure that the number is
in the range [min, max], and store it in *n.
It is similar to NetBSD's strtoi(3) and strtou(3), which
themselves are similar to strtol(3) and strtoul(3).
Arguments
T
The integer type used for the number.
n
A pointer to an integer. The parsed number will be
stored there.
s
See strtol(3).
endp
See strtol(3). A difference with strtol(3) is that this
macro is const-correct. If 's' has type 'const char *',
then 'endp' must have type 'const char **', whereas if
's' has type 'char *', 'endp' must have type 'char **'.
base
See strtol(3).
min
max
See strtoi(3) and strtou(3).
An important difference with NetBSD's strtou(3) is that
a2i() (with an unsigned type T) doesn't intepret any
negative numbers as if they were large positive numbers.
a2i() respects the limits [min, max] as one would
intuitively expect.
Return value
On success, 0 is returned.
On error, -1 is returned and errno is set to indicate the error.