libite 2.6.1
|
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
Go to the source code of this file.
Macros | |
#define | INVALID 1 |
#define | TOOSMALL 2 |
#define | TOOLARGE 3 |
#define | LLONG_MAX 0x7fffffffffffffffLL |
#define | LLONG_MIN (-0x7fffffffffffffffLL - 1) |
Functions | |
long long | strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp) |
#define INVALID 1 |
internal
Definition at line 33 of file strtonum.c.
#define LLONG_MAX 0x7fffffffffffffffLL |
internal
Definition at line 38 of file strtonum.c.
#define LLONG_MIN (-0x7fffffffffffffffLL - 1) |
internal
Definition at line 42 of file strtonum.c.
#define TOOLARGE 3 |
internal
Definition at line 35 of file strtonum.c.
#define TOOSMALL 2 |
internal
Definition at line 34 of file strtonum.c.
long long strtonum | ( | const char * | numstr, |
long long | minval, | ||
long long | maxval, | ||
const char ** | errstrp ) |
Reliably convert string value to an integer
numstr | String to convert to a number |
minval | Lower bound to check number against |
maxval | Upper bound to check number against |
errstrp | Pointer to error string |
This function converts the string in numstr
to a long long value. The function was designed to facilitate safe, robust programming and overcome the shortcomings of the atoi(3) and strtol(3) family of interfaces.
The string may begin with an arbitrary amount of whitespace (as determined by isspace(3)) followed by a single optional ‘+’ or ‘-’ sign.
The remainder of the string is converted to a long long value according to base 10.
The value obtained is then checked against the provided minval
and maxval
bounds. If errstrp
is non-NULL, strtonum() stores an error string in *errstrp
indicating the failure.
errstrp
points to an error message. *errstr*
is set to NULL
on success; this fact can be used to differentiate a successful return of 0 from an error. Definition at line 75 of file strtonum.c.