]>
git.cameronkatri.com Git - mandoc.git/blob - compat_strtonum.c
1 /* $Id: compat_strtonum.c,v 1.2 2020/06/15 01:37:15 schwarze Exp $ */
2 /* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */
5 * Copyright (c) 2004 Ted Unangst and Todd Miller
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 strtonum(const char *numstr
, long long minval
, long long maxval
,
42 { "invalid", EINVAL
},
43 { "too small", ERANGE
},
44 { "too large", ERANGE
},
49 if (minval
> maxval
) {
52 ll
= strtoll(numstr
, &ep
, 10);
53 if (numstr
== ep
|| *ep
!= '\0')
55 else if ((ll
== LLONG_MIN
&& errno
== ERANGE
) || ll
< minval
)
57 else if ((ll
== LLONG_MAX
&& errno
== ERANGE
) || ll
> maxval
)
61 *errstrp
= ev
[error
].errstr
;
62 errno
= ev
[error
].err
;