| Main index | Section 3 | Options |
#include <stdlib.h>
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 errstr is non-null, strtonum() stores an error string in *errstr indicating the failure.
int iterations; const char *errstr;iterations = strtonum(optarg, 1, 64, &errstr); if (errstr != NULL) errx(1, "number of iterations is %s: %s", errstr, optarg);
The above example will guarantee that the value of iterations is between 1 and 64 (inclusive).
| [ERANGE] | |
| The given string was out of range. | |
| [EINVAL] | |
| The given string did not consist solely of digit characters. | |
| [EINVAL] | |
| The supplied minval was larger than maxval. | |
If an error occurs, errstr will be set to one of the following strings:
| too large | The result was larger than the provided maximum value. |
| too small | The result was smaller than the provided minimum value. |
| invalid | The string did not consist solely of digit characters. |
| STRTONUM (3) | April 29, 2004 |
| Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Do you laugh when the waiter drops a tray full of dishes? Unix weenies do. They're the first ones to laugh at hapless users, trying to figure out an error message that doesn't have anything to do with what they just typed. | ” |
| — The Unix Haters' handbook | ||