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