diff options
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | crypto/CMakeLists.txt | 5 | ||||
-rw-r--r-- | crypto/compat/getopt_long.c | 528 | ||||
-rw-r--r-- | include/compat/getopt.h | 50 | ||||
-rw-r--r-- | include/compat/unistd.h | 4 | ||||
-rw-r--r-- | m4/check-libc.m4 | 3 | ||||
-rw-r--r-- | patches/bn_isqrt.c.patch | 18 | ||||
-rw-r--r-- | patches/handshake_table.c.patch | 18 |
8 files changed, 594 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b8863c4..6f0d5cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -176,6 +176,11 @@ if(HAVE_ASPRINTF) | |||
176 | add_definitions(-DHAVE_ASPRINTF) | 176 | add_definitions(-DHAVE_ASPRINTF) |
177 | endif() | 177 | endif() |
178 | 178 | ||
179 | check_function_exists(getopt HAVE_GETOPT) | ||
180 | if(HAVE_GETOPT) | ||
181 | add_definitions(-DHAVE_GETOPT) | ||
182 | endif() | ||
183 | |||
179 | check_function_exists(reallocarray HAVE_REALLOCARRAY) | 184 | check_function_exists(reallocarray HAVE_REALLOCARRAY) |
180 | if(HAVE_REALLOCARRAY) | 185 | if(HAVE_REALLOCARRAY) |
181 | add_definitions(-DHAVE_REALLOCARRAY) | 186 | add_definitions(-DHAVE_REALLOCARRAY) |
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 0c86dd4..3fb2285 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt | |||
@@ -818,6 +818,11 @@ if(NOT HAVE_FREEZERO) | |||
818 | set(EXTRA_EXPORT ${EXTRA_EXPORT} freezero) | 818 | set(EXTRA_EXPORT ${EXTRA_EXPORT} freezero) |
819 | endif() | 819 | endif() |
820 | 820 | ||
821 | if(NOT HAVE_GETOPT) | ||
822 | set(CRYPTO_SRC ${CRYPTO_SRC} compat/getopt_long.c) | ||
823 | set(EXTRA_EXPORT ${EXTRA_EXPORT} getopt) | ||
824 | endif() | ||
825 | |||
821 | if(NOT HAVE_GETPAGESIZE) | 826 | if(NOT HAVE_GETPAGESIZE) |
822 | set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c) | 827 | set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c) |
823 | endif() | 828 | endif() |
diff --git a/crypto/compat/getopt_long.c b/crypto/compat/getopt_long.c new file mode 100644 index 0000000..546c541 --- /dev/null +++ b/crypto/compat/getopt_long.c | |||
@@ -0,0 +1,528 @@ | |||
1 | /* $OpenBSD: getopt_long.c,v 1.32 2020/05/27 22:25:09 schwarze Exp $ */ | ||
2 | /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 2002 Todd C. Miller <millert@openbsd.org> | ||
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 | * Sponsored in part by the Defense Advanced Research Projects | ||
20 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
21 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. | ||
22 | */ | ||
23 | /*- | ||
24 | * Copyright (c) 2000 The NetBSD Foundation, Inc. | ||
25 | * All rights reserved. | ||
26 | * | ||
27 | * This code is derived from software contributed to The NetBSD Foundation | ||
28 | * by Dieter Baron and Thomas Klausner. | ||
29 | * | ||
30 | * Redistribution and use in source and binary forms, with or without | ||
31 | * modification, are permitted provided that the following conditions | ||
32 | * are met: | ||
33 | * 1. Redistributions of source code must retain the above copyright | ||
34 | * notice, this list of conditions and the following disclaimer. | ||
35 | * 2. Redistributions in binary form must reproduce the above copyright | ||
36 | * notice, this list of conditions and the following disclaimer in the | ||
37 | * documentation and/or other materials provided with the distribution. | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
40 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
41 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
43 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
44 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
45 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
46 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
47 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
49 | * POSSIBILITY OF SUCH DAMAGE. | ||
50 | */ | ||
51 | |||
52 | #include <err.h> | ||
53 | #include <errno.h> | ||
54 | #include <getopt.h> | ||
55 | #include <stdlib.h> | ||
56 | #include <string.h> | ||
57 | |||
58 | #define no_argument 0 | ||
59 | #define required_argument 1 | ||
60 | #define optional_argument 2 | ||
61 | |||
62 | struct option { | ||
63 | /* name of long option */ | ||
64 | const char *name; | ||
65 | /* | ||
66 | * one of no_argument, required_argument, and optional_argument: | ||
67 | * whether option takes an argument | ||
68 | */ | ||
69 | int has_arg; | ||
70 | /* if not NULL, set *flag to val when option found */ | ||
71 | int *flag; | ||
72 | /* if flag not NULL, value to set *flag to; else return value */ | ||
73 | int val; | ||
74 | }; | ||
75 | |||
76 | int opterr = 1; /* if error message should be printed */ | ||
77 | int optind = 1; /* index into parent argv vector */ | ||
78 | int optopt = '?'; /* character checked for validity */ | ||
79 | int optreset; /* reset getopt */ | ||
80 | char *optarg; /* argument associated with option */ | ||
81 | |||
82 | #if 0 | ||
83 | /* DEF_* only work on initialized (non-COMMON) variables */ | ||
84 | #endif | ||
85 | |||
86 | #define PRINT_ERROR ((opterr) && (*options != ':')) | ||
87 | |||
88 | #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ | ||
89 | #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ | ||
90 | #define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ | ||
91 | |||
92 | /* return values */ | ||
93 | #define BADCH (int)'?' | ||
94 | #define BADARG ((*options == ':') ? (int)':' : (int)'?') | ||
95 | #define INORDER (int)1 | ||
96 | |||
97 | #define EMSG "" | ||
98 | |||
99 | static int getopt_internal(int, char * const *, const char *, | ||
100 | const struct option *, int *, int); | ||
101 | static int parse_long_options(char * const *, const char *, | ||
102 | const struct option *, int *, int, int); | ||
103 | static int gcd(int, int); | ||
104 | static void permute_args(int, int, int, char * const *); | ||
105 | |||
106 | static char *place = EMSG; /* option letter processing */ | ||
107 | |||
108 | /* XXX: set optreset to 1 rather than these two */ | ||
109 | static int nonopt_start = -1; /* first non option argument (for permute) */ | ||
110 | static int nonopt_end = -1; /* first option after non options (for permute) */ | ||
111 | |||
112 | /* Error messages */ | ||
113 | static const char recargchar[] = "option requires an argument -- %c"; | ||
114 | static const char recargstring[] = "option requires an argument -- %s"; | ||
115 | static const char ambig[] = "ambiguous option -- %.*s"; | ||
116 | static const char noarg[] = "option doesn't take an argument -- %.*s"; | ||
117 | static const char illoptchar[] = "unknown option -- %c"; | ||
118 | static const char illoptstring[] = "unknown option -- %s"; | ||
119 | |||
120 | /* | ||
121 | * Compute the greatest common divisor of a and b. | ||
122 | */ | ||
123 | static int | ||
124 | gcd(int a, int b) | ||
125 | { | ||
126 | int c; | ||
127 | |||
128 | c = a % b; | ||
129 | while (c != 0) { | ||
130 | a = b; | ||
131 | b = c; | ||
132 | c = a % b; | ||
133 | } | ||
134 | |||
135 | return (b); | ||
136 | } | ||
137 | |||
138 | /* | ||
139 | * Exchange the block from nonopt_start to nonopt_end with the block | ||
140 | * from nonopt_end to opt_end (keeping the same order of arguments | ||
141 | * in each block). | ||
142 | */ | ||
143 | static void | ||
144 | permute_args(int panonopt_start, int panonopt_end, int opt_end, | ||
145 | char * const *nargv) | ||
146 | { | ||
147 | int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; | ||
148 | char *swap; | ||
149 | |||
150 | /* | ||
151 | * compute lengths of blocks and number and size of cycles | ||
152 | */ | ||
153 | nnonopts = panonopt_end - panonopt_start; | ||
154 | nopts = opt_end - panonopt_end; | ||
155 | ncycle = gcd(nnonopts, nopts); | ||
156 | cyclelen = (opt_end - panonopt_start) / ncycle; | ||
157 | |||
158 | for (i = 0; i < ncycle; i++) { | ||
159 | cstart = panonopt_end+i; | ||
160 | pos = cstart; | ||
161 | for (j = 0; j < cyclelen; j++) { | ||
162 | if (pos >= panonopt_end) | ||
163 | pos -= nnonopts; | ||
164 | else | ||
165 | pos += nopts; | ||
166 | swap = nargv[pos]; | ||
167 | ((char **)nargv)[pos] = nargv[cstart]; | ||
168 | ((char **)nargv)[cstart] = swap; | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | |||
173 | /* | ||
174 | * parse_long_options -- | ||
175 | * Parse long options in argc/argv argument vector. | ||
176 | * Returns -1 if short_too is set and the option does not match long_options. | ||
177 | */ | ||
178 | static int | ||
179 | parse_long_options(char * const *nargv, const char *options, | ||
180 | const struct option *long_options, int *idx, int short_too, int flags) | ||
181 | { | ||
182 | char *current_argv, *has_equal; | ||
183 | size_t current_argv_len; | ||
184 | int i, match, exact_match, second_partial_match; | ||
185 | |||
186 | current_argv = place; | ||
187 | match = -1; | ||
188 | exact_match = 0; | ||
189 | second_partial_match = 0; | ||
190 | |||
191 | optind++; | ||
192 | |||
193 | if ((has_equal = strchr(current_argv, '=')) != NULL) { | ||
194 | /* argument found (--option=arg) */ | ||
195 | current_argv_len = has_equal - current_argv; | ||
196 | has_equal++; | ||
197 | } else | ||
198 | current_argv_len = strlen(current_argv); | ||
199 | |||
200 | for (i = 0; long_options[i].name; i++) { | ||
201 | /* find matching long option */ | ||
202 | if (strncmp(current_argv, long_options[i].name, | ||
203 | current_argv_len)) | ||
204 | continue; | ||
205 | |||
206 | if (strlen(long_options[i].name) == current_argv_len) { | ||
207 | /* exact match */ | ||
208 | match = i; | ||
209 | exact_match = 1; | ||
210 | break; | ||
211 | } | ||
212 | /* | ||
213 | * If this is a known short option, don't allow | ||
214 | * a partial match of a single character. | ||
215 | */ | ||
216 | if (short_too && current_argv_len == 1) | ||
217 | continue; | ||
218 | |||
219 | if (match == -1) /* first partial match */ | ||
220 | match = i; | ||
221 | else if ((flags & FLAG_LONGONLY) || | ||
222 | long_options[i].has_arg != long_options[match].has_arg || | ||
223 | long_options[i].flag != long_options[match].flag || | ||
224 | long_options[i].val != long_options[match].val) | ||
225 | second_partial_match = 1; | ||
226 | } | ||
227 | if (!exact_match && second_partial_match) { | ||
228 | /* ambiguous abbreviation */ | ||
229 | if (PRINT_ERROR) | ||
230 | warnx(ambig, (int)current_argv_len, current_argv); | ||
231 | optopt = 0; | ||
232 | return (BADCH); | ||
233 | } | ||
234 | if (match != -1) { /* option found */ | ||
235 | if (long_options[match].has_arg == no_argument | ||
236 | && has_equal) { | ||
237 | if (PRINT_ERROR) | ||
238 | warnx(noarg, (int)current_argv_len, | ||
239 | current_argv); | ||
240 | /* | ||
241 | * XXX: GNU sets optopt to val regardless of flag | ||
242 | */ | ||
243 | if (long_options[match].flag == NULL) | ||
244 | optopt = long_options[match].val; | ||
245 | else | ||
246 | optopt = 0; | ||
247 | return (BADARG); | ||
248 | } | ||
249 | if (long_options[match].has_arg == required_argument || | ||
250 | long_options[match].has_arg == optional_argument) { | ||
251 | if (has_equal) | ||
252 | optarg = has_equal; | ||
253 | else if (long_options[match].has_arg == | ||
254 | required_argument) { | ||
255 | /* | ||
256 | * optional argument doesn't use next nargv | ||
257 | */ | ||
258 | optarg = nargv[optind++]; | ||
259 | } | ||
260 | } | ||
261 | if ((long_options[match].has_arg == required_argument) | ||
262 | && (optarg == NULL)) { | ||
263 | /* | ||
264 | * Missing argument; leading ':' indicates no error | ||
265 | * should be generated. | ||
266 | */ | ||
267 | if (PRINT_ERROR) | ||
268 | warnx(recargstring, | ||
269 | current_argv); | ||
270 | /* | ||
271 | * XXX: GNU sets optopt to val regardless of flag | ||
272 | */ | ||
273 | if (long_options[match].flag == NULL) | ||
274 | optopt = long_options[match].val; | ||
275 | else | ||
276 | optopt = 0; | ||
277 | --optind; | ||
278 | return (BADARG); | ||
279 | } | ||
280 | } else { /* unknown option */ | ||
281 | if (short_too) { | ||
282 | --optind; | ||
283 | return (-1); | ||
284 | } | ||
285 | if (PRINT_ERROR) | ||
286 | warnx(illoptstring, current_argv); | ||
287 | optopt = 0; | ||
288 | return (BADCH); | ||
289 | } | ||
290 | if (idx) | ||
291 | *idx = match; | ||
292 | if (long_options[match].flag) { | ||
293 | *long_options[match].flag = long_options[match].val; | ||
294 | return (0); | ||
295 | } else | ||
296 | return (long_options[match].val); | ||
297 | } | ||
298 | |||
299 | /* | ||
300 | * getopt_internal -- | ||
301 | * Parse argc/argv argument vector. Called by user level routines. | ||
302 | */ | ||
303 | static int | ||
304 | getopt_internal(int nargc, char * const *nargv, const char *options, | ||
305 | const struct option *long_options, int *idx, int flags) | ||
306 | { | ||
307 | char *oli; /* option letter list index */ | ||
308 | int optchar, short_too; | ||
309 | static int posixly_correct = -1; | ||
310 | |||
311 | if (options == NULL) | ||
312 | return (-1); | ||
313 | |||
314 | /* | ||
315 | * XXX Some GNU programs (like cvs) set optind to 0 instead of | ||
316 | * XXX using optreset. Work around this braindamage. | ||
317 | */ | ||
318 | if (optind == 0) | ||
319 | optind = optreset = 1; | ||
320 | |||
321 | /* | ||
322 | * Disable GNU extensions if POSIXLY_CORRECT is set or options | ||
323 | * string begins with a '+'. | ||
324 | */ | ||
325 | if (posixly_correct == -1 || optreset) | ||
326 | posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); | ||
327 | if (*options == '-') | ||
328 | flags |= FLAG_ALLARGS; | ||
329 | else if (posixly_correct || *options == '+') | ||
330 | flags &= ~FLAG_PERMUTE; | ||
331 | if (*options == '+' || *options == '-') | ||
332 | options++; | ||
333 | |||
334 | optarg = NULL; | ||
335 | if (optreset) | ||
336 | nonopt_start = nonopt_end = -1; | ||
337 | start: | ||
338 | if (optreset || !*place) { /* update scanning pointer */ | ||
339 | optreset = 0; | ||
340 | if (optind >= nargc) { /* end of argument vector */ | ||
341 | place = EMSG; | ||
342 | if (nonopt_end != -1) { | ||
343 | /* do permutation, if we have to */ | ||
344 | permute_args(nonopt_start, nonopt_end, | ||
345 | optind, nargv); | ||
346 | optind -= nonopt_end - nonopt_start; | ||
347 | } | ||
348 | else if (nonopt_start != -1) { | ||
349 | /* | ||
350 | * If we skipped non-options, set optind | ||
351 | * to the first of them. | ||
352 | */ | ||
353 | optind = nonopt_start; | ||
354 | } | ||
355 | nonopt_start = nonopt_end = -1; | ||
356 | return (-1); | ||
357 | } | ||
358 | if (*(place = nargv[optind]) != '-' || | ||
359 | (place[1] == '\0' && strchr(options, '-') == NULL)) { | ||
360 | place = EMSG; /* found non-option */ | ||
361 | if (flags & FLAG_ALLARGS) { | ||
362 | /* | ||
363 | * GNU extension: | ||
364 | * return non-option as argument to option 1 | ||
365 | */ | ||
366 | optarg = nargv[optind++]; | ||
367 | return (INORDER); | ||
368 | } | ||
369 | if (!(flags & FLAG_PERMUTE)) { | ||
370 | /* | ||
371 | * If no permutation wanted, stop parsing | ||
372 | * at first non-option. | ||
373 | */ | ||
374 | return (-1); | ||
375 | } | ||
376 | /* do permutation */ | ||
377 | if (nonopt_start == -1) | ||
378 | nonopt_start = optind; | ||
379 | else if (nonopt_end != -1) { | ||
380 | permute_args(nonopt_start, nonopt_end, | ||
381 | optind, nargv); | ||
382 | nonopt_start = optind - | ||
383 | (nonopt_end - nonopt_start); | ||
384 | nonopt_end = -1; | ||
385 | } | ||
386 | optind++; | ||
387 | /* process next argument */ | ||
388 | goto start; | ||
389 | } | ||
390 | if (nonopt_start != -1 && nonopt_end == -1) | ||
391 | nonopt_end = optind; | ||
392 | |||
393 | /* | ||
394 | * If we have "-" do nothing, if "--" we are done. | ||
395 | */ | ||
396 | if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { | ||
397 | optind++; | ||
398 | place = EMSG; | ||
399 | /* | ||
400 | * We found an option (--), so if we skipped | ||
401 | * non-options, we have to permute. | ||
402 | */ | ||
403 | if (nonopt_end != -1) { | ||
404 | permute_args(nonopt_start, nonopt_end, | ||
405 | optind, nargv); | ||
406 | optind -= nonopt_end - nonopt_start; | ||
407 | } | ||
408 | nonopt_start = nonopt_end = -1; | ||
409 | return (-1); | ||
410 | } | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * Check long options if: | ||
415 | * 1) we were passed some | ||
416 | * 2) the arg is not just "-" | ||
417 | * 3) either the arg starts with -- we are getopt_long_only() | ||
418 | */ | ||
419 | if (long_options != NULL && place != nargv[optind] && | ||
420 | (*place == '-' || (flags & FLAG_LONGONLY))) { | ||
421 | short_too = 0; | ||
422 | if (*place == '-') | ||
423 | place++; /* --foo long option */ | ||
424 | else if (*place != ':' && strchr(options, *place) != NULL) | ||
425 | short_too = 1; /* could be short option too */ | ||
426 | |||
427 | optchar = parse_long_options(nargv, options, long_options, | ||
428 | idx, short_too, flags); | ||
429 | if (optchar != -1) { | ||
430 | place = EMSG; | ||
431 | return (optchar); | ||
432 | } | ||
433 | } | ||
434 | |||
435 | if ((optchar = (int)*place++) == (int)':' || | ||
436 | (oli = strchr(options, optchar)) == NULL) { | ||
437 | if (!*place) | ||
438 | ++optind; | ||
439 | if (PRINT_ERROR) | ||
440 | warnx(illoptchar, optchar); | ||
441 | optopt = optchar; | ||
442 | return (BADCH); | ||
443 | } | ||
444 | if (long_options != NULL && optchar == 'W' && oli[1] == ';') { | ||
445 | /* -W long-option */ | ||
446 | if (*place) /* no space */ | ||
447 | /* NOTHING */; | ||
448 | else if (++optind >= nargc) { /* no arg */ | ||
449 | place = EMSG; | ||
450 | if (PRINT_ERROR) | ||
451 | warnx(recargchar, optchar); | ||
452 | optopt = optchar; | ||
453 | return (BADARG); | ||
454 | } else /* white space */ | ||
455 | place = nargv[optind]; | ||
456 | optchar = parse_long_options(nargv, options, long_options, | ||
457 | idx, 0, flags); | ||
458 | place = EMSG; | ||
459 | return (optchar); | ||
460 | } | ||
461 | if (*++oli != ':') { /* doesn't take argument */ | ||
462 | if (!*place) | ||
463 | ++optind; | ||
464 | } else { /* takes (optional) argument */ | ||
465 | optarg = NULL; | ||
466 | if (*place) /* no white space */ | ||
467 | optarg = place; | ||
468 | else if (oli[1] != ':') { /* arg not optional */ | ||
469 | if (++optind >= nargc) { /* no arg */ | ||
470 | place = EMSG; | ||
471 | if (PRINT_ERROR) | ||
472 | warnx(recargchar, optchar); | ||
473 | optopt = optchar; | ||
474 | return (BADARG); | ||
475 | } else | ||
476 | optarg = nargv[optind]; | ||
477 | } | ||
478 | place = EMSG; | ||
479 | ++optind; | ||
480 | } | ||
481 | /* dump back option letter */ | ||
482 | return (optchar); | ||
483 | } | ||
484 | |||
485 | /* | ||
486 | * getopt -- | ||
487 | * Parse argc/argv argument vector. | ||
488 | */ | ||
489 | int | ||
490 | getopt(int nargc, char * const *nargv, const char *options) | ||
491 | { | ||
492 | |||
493 | /* | ||
494 | * We don't pass FLAG_PERMUTE to getopt_internal() since | ||
495 | * the BSD getopt(3) (unlike GNU) has never done this. | ||
496 | * | ||
497 | * Furthermore, since many privileged programs call getopt() | ||
498 | * before dropping privileges it makes sense to keep things | ||
499 | * as simple (and bug-free) as possible. | ||
500 | */ | ||
501 | return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); | ||
502 | } | ||
503 | |||
504 | /* | ||
505 | * getopt_long -- | ||
506 | * Parse argc/argv argument vector. | ||
507 | */ | ||
508 | int | ||
509 | getopt_long(int nargc, char * const *nargv, const char *options, | ||
510 | const struct option *long_options, int *idx) | ||
511 | { | ||
512 | |||
513 | return (getopt_internal(nargc, nargv, options, long_options, idx, | ||
514 | FLAG_PERMUTE)); | ||
515 | } | ||
516 | |||
517 | /* | ||
518 | * getopt_long_only -- | ||
519 | * Parse argc/argv argument vector. | ||
520 | */ | ||
521 | int | ||
522 | getopt_long_only(int nargc, char * const *nargv, const char *options, | ||
523 | const struct option *long_options, int *idx) | ||
524 | { | ||
525 | |||
526 | return (getopt_internal(nargc, nargv, options, long_options, idx, | ||
527 | FLAG_PERMUTE|FLAG_LONGONLY)); | ||
528 | } | ||
diff --git a/include/compat/getopt.h b/include/compat/getopt.h new file mode 100644 index 0000000..8cc3207 --- /dev/null +++ b/include/compat/getopt.h | |||
@@ -0,0 +1,50 @@ | |||
1 | /* $OpenBSD: getopt.h,v 1.3 2013/11/22 21:32:49 millert Exp $ */ | ||
2 | /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2000 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Dieter Baron and Thomas Klausner. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #ifdef HAVE_GETOPT | ||
34 | |||
35 | #include_next <getopt.h> | ||
36 | |||
37 | #else | ||
38 | |||
39 | #ifndef _GETOPT_DEFINED_ | ||
40 | #define _GETOPT_DEFINED_ | ||
41 | int getopt(int, char * const *, const char *); | ||
42 | |||
43 | extern char *optarg; /* getopt(3) external variables */ | ||
44 | extern int opterr; | ||
45 | extern int optind; | ||
46 | extern int optopt; | ||
47 | extern int optreset; | ||
48 | #endif | ||
49 | |||
50 | #endif /* HAVE_GETOPT */ | ||
diff --git a/include/compat/unistd.h b/include/compat/unistd.h index 5e6ab1d..2583a6e 100644 --- a/include/compat/unistd.h +++ b/include/compat/unistd.h | |||
@@ -64,6 +64,10 @@ int getentropy(void *buf, size_t buflen); | |||
64 | #endif | 64 | #endif |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #ifndef HAVE_GETOPT | ||
68 | #include <getopt.h> | ||
69 | #endif | ||
70 | |||
67 | #ifndef HAVE_GETPAGESIZE | 71 | #ifndef HAVE_GETPAGESIZE |
68 | int getpagesize(void); | 72 | int getpagesize(void); |
69 | #endif | 73 | #endif |
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 68a4f88..dc8d6bd 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 | |||
@@ -11,7 +11,7 @@ AC_CHECK_FUNCS([asprintf freezero memmem]) | |||
11 | AC_CHECK_FUNCS([readpassphrase reallocarray recallocarray]) | 11 | AC_CHECK_FUNCS([readpassphrase reallocarray recallocarray]) |
12 | AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) | 12 | AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) |
13 | AC_CHECK_FUNCS([timegm _mkgmtime timespecsub]) | 13 | AC_CHECK_FUNCS([timegm _mkgmtime timespecsub]) |
14 | AC_CHECK_FUNCS([getprogname syslog syslog_r]) | 14 | AC_CHECK_FUNCS([getopt getprogname syslog syslog_r]) |
15 | AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ | 15 | AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ |
16 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | 16 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
17 | #include <unistd.h> | 17 | #include <unistd.h> |
@@ -25,6 +25,7 @@ AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ | |||
25 | AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) | 25 | AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) |
26 | AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) | 26 | AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) |
27 | AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) | 27 | AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) |
28 | AM_CONDITIONAL([HAVE_GETOPT], [test "x$ac_cv_func_getopt" = xyes]) | ||
28 | AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) | 29 | AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) |
29 | AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes]) | 30 | AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes]) |
30 | AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) | 31 | AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) |
diff --git a/patches/bn_isqrt.c.patch b/patches/bn_isqrt.c.patch deleted file mode 100644 index 5f2a568..0000000 --- a/patches/bn_isqrt.c.patch +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | --- tests/bn_isqrt.c.orig Fri Dec 9 11:05:26 2022 | ||
2 | +++ tests/bn_isqrt.c Fri Dec 9 11:12:37 2022 | ||
3 | @@ -306,6 +306,7 @@ main(int argc, char *argv[]) | ||
4 | int ch; | ||
5 | int failed = 0, print = 0; | ||
6 | |||
7 | +#ifndef _MSC_VER | ||
8 | while ((ch = getopt(argc, argv, "C")) != -1) { | ||
9 | switch (ch) { | ||
10 | case 'C': | ||
11 | @@ -316,6 +317,7 @@ main(int argc, char *argv[]) | ||
12 | break; | ||
13 | } | ||
14 | } | ||
15 | +#endif | ||
16 | |||
17 | if (print) | ||
18 | return check_tables(1); | ||
diff --git a/patches/handshake_table.c.patch b/patches/handshake_table.c.patch deleted file mode 100644 index f3a4004..0000000 --- a/patches/handshake_table.c.patch +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | --- tests/handshake_table.c.orig Tue Mar 15 11:37:03 2022 | ||
2 | +++ tests/handshake_table.c Mon Mar 21 05:26:15 2022 | ||
3 | @@ -518,6 +518,7 @@ | ||
4 | unsigned int depth = 0; | ||
5 | int ch, graphviz = 0, print = 0; | ||
6 | |||
7 | +#ifndef _MSC_VER | ||
8 | while ((ch = getopt(argc, argv, "Cg")) != -1) { | ||
9 | switch (ch) { | ||
10 | case 'C': | ||
11 | @@ -535,6 +536,7 @@ | ||
12 | |||
13 | if (argc != 0) | ||
14 | usage(); | ||
15 | +#endif | ||
16 | |||
17 | if (graphviz && print) | ||
18 | usage(); | ||