13 /* --------------------------------------------------------------------------- */
14 /* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */
17 * Copyright (c) 2004 Ted Unangst and Todd Miller
18 * All rights reserved.
20 * Permission to use, copy, modify, and distribute this software for any
21 * purpose with or without fee is hereby granted, provided that the above
22 * copyright notice and this permission notice appear in all copies.
24 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
25 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
27 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
28 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
29 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
30 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38 strtonum(const char *numstr, long long minval, long long maxval,
49 { "invalid", EINVAL },
50 { "too small", ERANGE },
51 { "too large", ERANGE },
59 ll = strtoll(numstr, &ep, 10);
60 if (numstr == ep || *ep != '\0')
62 else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
64 else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
68 *errstrp = ev[error].errstr;
69 errno = ev[error].err;