diff options
author | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
commit | eb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch) | |
tree | edb6da6af7e865d488dc1a29309f1e1ec226e603 /src/lib/libc/stdlib/strtonum.c | |
parent | 247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff) | |
download | openbsd-eb8dd9dca1228af0cd132f515509051ecfabf6f6.tar.gz openbsd-eb8dd9dca1228af0cd132f515509051ecfabf6f6.tar.bz2 openbsd-eb8dd9dca1228af0cd132f515509051ecfabf6f6.zip |
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/lib/libc/stdlib/strtonum.c')
-rw-r--r-- | src/lib/libc/stdlib/strtonum.c | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/lib/libc/stdlib/strtonum.c b/src/lib/libc/stdlib/strtonum.c deleted file mode 100644 index ad22d1c30c..0000000000 --- a/src/lib/libc/stdlib/strtonum.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2004 Ted Unangst and Todd Miller | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Permission to use, copy, modify, and distribute this software for any | ||
8 | * purpose with or without fee is hereby granted, provided that the above | ||
9 | * copyright notice and this permission notice appear in all copies. | ||
10 | * | ||
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #include <errno.h> | ||
21 | #include <limits.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | #define INVALID 1 | ||
25 | #define TOOSMALL 2 | ||
26 | #define TOOLARGE 3 | ||
27 | |||
28 | long long | ||
29 | strtonum(const char *numstr, long long minval, long long maxval, | ||
30 | const char **errstrp) | ||
31 | { | ||
32 | long long ll = 0; | ||
33 | int error = 0; | ||
34 | char *ep; | ||
35 | struct errval { | ||
36 | const char *errstr; | ||
37 | int err; | ||
38 | } ev[4] = { | ||
39 | { NULL, 0 }, | ||
40 | { "invalid", EINVAL }, | ||
41 | { "too small", ERANGE }, | ||
42 | { "too large", ERANGE }, | ||
43 | }; | ||
44 | |||
45 | ev[0].err = errno; | ||
46 | errno = 0; | ||
47 | if (minval > maxval) { | ||
48 | error = INVALID; | ||
49 | } else { | ||
50 | ll = strtoll(numstr, &ep, 10); | ||
51 | if (numstr == ep || *ep != '\0') | ||
52 | error = INVALID; | ||
53 | else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) | ||
54 | error = TOOSMALL; | ||
55 | else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) | ||
56 | error = TOOLARGE; | ||
57 | } | ||
58 | if (errstrp != NULL) | ||
59 | *errstrp = ev[error].errstr; | ||
60 | errno = ev[error].err; | ||
61 | if (error) | ||
62 | ll = 0; | ||
63 | |||
64 | return (ll); | ||
65 | } | ||
66 | DEF_WEAK(strtonum); | ||