Debian Codegraph @

compat/strtonum.c

raw symbols SCIP
1 /* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */cxx . . $ `<file>/compat/strtonum.c`/
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 #include "compat.h"cxx . . $ `<file>/compat/compat.h`/
25
26 #define INVALIDcxx . . $ `compat/strtonum.c:26:9`! 1
27 #define TOOSMALLcxx . . $ `compat/strtonum.c:27:9`! 2
28 #define TOOLARGEcxx . . $ `compat/strtonum.c:28:9`! 3
29
30 long long
31 strtonumcxx . . $ strtonum(2426cb88955c24b7).(const char *numstr, long long minval, long long maxval,
32 const char **errstrp)
33 {
34 long long ll = 0;
35 int error = 0;
36 char *ep;
37 struct errvalcxx . . $ strtonum(2426cb88955c24b7).errval# {
38 const char *errstrcxx . . $ strtonum(2426cb88955c24b7).errval#errstr.;
39 int errcxx . . $ strtonum(2426cb88955c24b7).errval#err.;
40 } ev[4] = {
41 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0 },
42 { "invalid", EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`! },
43 { "too small", ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`! },
44 { "too large", ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`! },
45 };
46
47 ev[0].errcxx . . $ strtonum(2426cb88955c24b7).errval#err. = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
48 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
49 if (minval > maxval) {
50 error = INVALIDcxx . . $ `compat/strtonum.c:26:9`!;
51 } else {
52 ll = strtollcxx . . $ strtoll(c50972e7488cbac6).(numstr, &ep, 10);
53 if (numstr == ep || *ep != '\0')
54 error = INVALIDcxx . . $ `compat/strtonum.c:26:9`!;
55 else if ((ll == LLONG_MINcxx . . $ `<external>/2419331716647297546/limits.h:140:10`! && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`!) || ll < minval)
56 error = TOOSMALLcxx . . $ `compat/strtonum.c:27:9`!;
57 else if ((ll == LLONG_MAXcxx . . $ `<external>/2419331716647297546/limits.h:142:10`! && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`!) || ll > maxval)
58 error = TOOLARGEcxx . . $ `compat/strtonum.c:28:9`!;
59 }
60 if (errstrp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
61 *errstrp = ev[error].errstrcxx . . $ strtonum(2426cb88955c24b7).errval#errstr.;
62 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ev[error].errcxx . . $ strtonum(2426cb88955c24b7).errval#err.;
63 if (error)
64 ll = 0;
65
66 return (ll);
67 }