uringmachine 0.16 → 0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.gitmodules +4 -0
- data/CHANGELOG.md +8 -0
- data/TODO.md +12 -3
- data/examples/bm_send.rb +86 -0
- data/ext/um/um.c +28 -1
- data/ext/um/um.h +3 -0
- data/ext/um/um_class.c +17 -0
- data/ext/um/um_utils.c +38 -15
- data/lib/uringmachine/version.rb +1 -1
- data/test/test_um.rb +76 -0
- data/vendor/libressl/.github/scripts/changelog.sh +74 -0
- data/vendor/libressl/.github/workflows/android.yml +35 -0
- data/vendor/libressl/.github/workflows/cifuzz.yml +33 -0
- data/vendor/libressl/.github/workflows/cmake-config.yml +98 -0
- data/vendor/libressl/.github/workflows/coverity.yml +69 -0
- data/vendor/libressl/.github/workflows/emscripten.yml +71 -0
- data/vendor/libressl/.github/workflows/fedora-rawhide.yml +39 -0
- data/vendor/libressl/.github/workflows/freebsd.yml +71 -0
- data/vendor/libressl/.github/workflows/linux.yml +71 -0
- data/vendor/libressl/.github/workflows/macos.yml +37 -0
- data/vendor/libressl/.github/workflows/release.yml +81 -0
- data/vendor/libressl/.github/workflows/rust-openssl.yml +47 -0
- data/vendor/libressl/.github/workflows/solaris.yml +37 -0
- data/vendor/libressl/.github/workflows/windows.yml +70 -0
- data/vendor/libressl/.gitignore +333 -0
- data/vendor/libressl/CMakeLists.txt +581 -0
- data/vendor/libressl/COPYING +133 -0
- data/vendor/libressl/ChangeLog +3280 -0
- data/vendor/libressl/FindLibreSSL.cmake +232 -0
- data/vendor/libressl/LibreSSLConfig.cmake.in +36 -0
- data/vendor/libressl/Makefile.am +60 -0
- data/vendor/libressl/Makefile.am.common +20 -0
- data/vendor/libressl/OPENBSD_BRANCH +1 -0
- data/vendor/libressl/README.md +238 -0
- data/vendor/libressl/README.mingw.md +43 -0
- data/vendor/libressl/apps/CMakeLists.txt +18 -0
- data/vendor/libressl/apps/Makefile.am +5 -0
- data/vendor/libressl/apps/nc/CMakeLists.txt +67 -0
- data/vendor/libressl/apps/nc/Makefile.am +64 -0
- data/vendor/libressl/apps/nc/compat/accept4.c +17 -0
- data/vendor/libressl/apps/nc/compat/readpassphrase.c +205 -0
- data/vendor/libressl/apps/nc/compat/socket.c +29 -0
- data/vendor/libressl/apps/nc/compat/sys/socket.h +30 -0
- data/vendor/libressl/apps/ocspcheck/CMakeLists.txt +44 -0
- data/vendor/libressl/apps/ocspcheck/Makefile.am +45 -0
- data/vendor/libressl/apps/ocspcheck/compat/.gitignore +0 -0
- data/vendor/libressl/apps/openssl/CMakeLists.txt +97 -0
- data/vendor/libressl/apps/openssl/Makefile.am +108 -0
- data/vendor/libressl/apps/openssl/apps_win.c +138 -0
- data/vendor/libressl/apps/openssl/certhash_win.c +13 -0
- data/vendor/libressl/apps/openssl/compat/clock_gettime_osx.c +26 -0
- data/vendor/libressl/apps/openssl/compat/poll_win.c +329 -0
- data/vendor/libressl/appveyor.yml +53 -0
- data/vendor/libressl/autogen.sh +15 -0
- data/vendor/libressl/check-release.sh +86 -0
- data/vendor/libressl/cmake_export_symbol.cmake +71 -0
- data/vendor/libressl/cmake_uninstall.cmake.in +36 -0
- data/vendor/libressl/config +17 -0
- data/vendor/libressl/configure.ac +165 -0
- data/vendor/libressl/crypto/CMakeLists.txt +863 -0
- data/vendor/libressl/crypto/Makefile.am +962 -0
- data/vendor/libressl/crypto/Makefile.am.arc4random +46 -0
- data/vendor/libressl/crypto/Makefile.am.elf-mips +14 -0
- data/vendor/libressl/crypto/Makefile.am.elf-mips64 +14 -0
- data/vendor/libressl/crypto/Makefile.am.elf-x86_64 +35 -0
- data/vendor/libressl/crypto/Makefile.am.macosx-x86_64 +35 -0
- data/vendor/libressl/crypto/Makefile.am.masm-x86_64 +22 -0
- data/vendor/libressl/crypto/Makefile.am.mingw64-x86_64 +23 -0
- data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_darwin.c +60 -0
- data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_linux.c +62 -0
- data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_none.c +26 -0
- data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_windows.c +36 -0
- data/vendor/libressl/crypto/arch/loongarch64/crypto_arch.h +21 -0
- data/vendor/libressl/crypto/arch/mips/crypto_arch.h +21 -0
- data/vendor/libressl/crypto/bn/arch/loongarch64/bn_arch.h +23 -0
- data/vendor/libressl/crypto/bn/arch/mips/bn_arch.h +24 -0
- data/vendor/libressl/crypto/compat/.gitignore +31 -0
- data/vendor/libressl/crypto/compat/arc4random.h +41 -0
- data/vendor/libressl/crypto/compat/b_win.c +55 -0
- data/vendor/libressl/crypto/compat/bsd-asprintf.c +96 -0
- data/vendor/libressl/crypto/compat/crypto_lock_win.c +56 -0
- data/vendor/libressl/crypto/compat/explicit_bzero_win.c +13 -0
- data/vendor/libressl/crypto/compat/freezero.c +32 -0
- data/vendor/libressl/crypto/compat/getdelim.c +78 -0
- data/vendor/libressl/crypto/compat/getline.c +40 -0
- data/vendor/libressl/crypto/compat/getopt_long.c +528 -0
- data/vendor/libressl/crypto/compat/getpagesize.c +18 -0
- data/vendor/libressl/crypto/compat/getprogname_linux.c +23 -0
- data/vendor/libressl/crypto/compat/getprogname_unimpl.c +7 -0
- data/vendor/libressl/crypto/compat/getprogname_windows.c +13 -0
- data/vendor/libressl/crypto/compat/posix_win.c +296 -0
- data/vendor/libressl/crypto/compat/syslog_r.c +19 -0
- data/vendor/libressl/crypto/compat/ui_openssl_win.c +334 -0
- data/vendor/libressl/dist.sh +22 -0
- data/vendor/libressl/gen-coverage-report.sh +58 -0
- data/vendor/libressl/gen-openbsd-tags.sh +20 -0
- data/vendor/libressl/include/CMakeLists.txt +61 -0
- data/vendor/libressl/include/Makefile.am +79 -0
- data/vendor/libressl/include/arch/loongarch64/opensslconf.h +150 -0
- data/vendor/libressl/include/arch/mips/opensslconf.h +150 -0
- data/vendor/libressl/include/compat/arpa/inet.h +15 -0
- data/vendor/libressl/include/compat/arpa/nameser.h +25 -0
- data/vendor/libressl/include/compat/cet.h +19 -0
- data/vendor/libressl/include/compat/dirent.h +17 -0
- data/vendor/libressl/include/compat/dirent_msvc.h +611 -0
- data/vendor/libressl/include/compat/endian.h +161 -0
- data/vendor/libressl/include/compat/err.h +95 -0
- data/vendor/libressl/include/compat/fcntl.h +32 -0
- data/vendor/libressl/include/compat/getopt.h +50 -0
- data/vendor/libressl/include/compat/limits.h +25 -0
- data/vendor/libressl/include/compat/netdb.h +10 -0
- data/vendor/libressl/include/compat/netinet/in.h +19 -0
- data/vendor/libressl/include/compat/netinet/ip.h +49 -0
- data/vendor/libressl/include/compat/netinet/tcp.h +10 -0
- data/vendor/libressl/include/compat/poll.h +63 -0
- data/vendor/libressl/include/compat/pthread.h +122 -0
- data/vendor/libressl/include/compat/readpassphrase.h +44 -0
- data/vendor/libressl/include/compat/resolv.h +24 -0
- data/vendor/libressl/include/compat/stdint.h +31 -0
- data/vendor/libressl/include/compat/stdio.h +65 -0
- data/vendor/libressl/include/compat/stdlib.h +57 -0
- data/vendor/libressl/include/compat/string.h +98 -0
- data/vendor/libressl/include/compat/sys/_null.h +18 -0
- data/vendor/libressl/include/compat/sys/ioctl.h +11 -0
- data/vendor/libressl/include/compat/sys/mman.h +19 -0
- data/vendor/libressl/include/compat/sys/param.h +15 -0
- data/vendor/libressl/include/compat/sys/queue.h +536 -0
- data/vendor/libressl/include/compat/sys/select.h +10 -0
- data/vendor/libressl/include/compat/sys/socket.h +18 -0
- data/vendor/libressl/include/compat/sys/stat.h +129 -0
- data/vendor/libressl/include/compat/sys/time.h +37 -0
- data/vendor/libressl/include/compat/sys/tree.h +1006 -0
- data/vendor/libressl/include/compat/sys/types.h +69 -0
- data/vendor/libressl/include/compat/sys/uio.h +17 -0
- data/vendor/libressl/include/compat/syslog.h +38 -0
- data/vendor/libressl/include/compat/time.h +59 -0
- data/vendor/libressl/include/compat/unistd.h +83 -0
- data/vendor/libressl/include/compat/win32netcompat.h +57 -0
- data/vendor/libressl/include/openssl/Makefile.am.tpl +45 -0
- data/vendor/libressl/libcrypto.pc.in +28 -0
- data/vendor/libressl/libressl.pub +2 -0
- data/vendor/libressl/libssl.pc.in +28 -0
- data/vendor/libressl/libtls.pc.in +28 -0
- data/vendor/libressl/m4/ax_add_fortify_source.m4 +80 -0
- data/vendor/libressl/m4/ax_check_compile_flag.m4 +53 -0
- data/vendor/libressl/m4/check-hardening-options.m4 +110 -0
- data/vendor/libressl/m4/check-libc.m4 +189 -0
- data/vendor/libressl/m4/check-os-options.m4 +181 -0
- data/vendor/libressl/m4/disable-compiler-warnings.m4 +44 -0
- data/vendor/libressl/man/CMakeLists.txt +26 -0
- data/vendor/libressl/man/links +2780 -0
- data/vendor/libressl/man/update_links.sh +25 -0
- data/vendor/libressl/openssl.pc.in +11 -0
- data/vendor/libressl/patches/bn_shift.patch +34 -0
- data/vendor/libressl/patches/crypto_arch.h.patch +34 -0
- data/vendor/libressl/patches/crypto_namespace.h.patch +22 -0
- data/vendor/libressl/patches/netcat.c.patch +178 -0
- data/vendor/libressl/patches/openssl.c.patch +12 -0
- data/vendor/libressl/patches/opensslfeatures.h.patch +49 -0
- data/vendor/libressl/patches/patch-amd64-crypto-cpu-caps.c.patch +20 -0
- data/vendor/libressl/patches/patch-i386-crypto-cpu-caps.c.patch +20 -0
- data/vendor/libressl/patches/speed.c.patch +114 -0
- data/vendor/libressl/patches/ssl_namespace.h.patch +21 -0
- data/vendor/libressl/patches/tls.h.patch +16 -0
- data/vendor/libressl/patches/tls_config.c.patch +15 -0
- data/vendor/libressl/patches/win32_amd64_bn_arch.h.patch +28 -0
- data/vendor/libressl/patches/windows_headers.patch +80 -0
- data/vendor/libressl/scripts/config.guess +1774 -0
- data/vendor/libressl/scripts/config.sub +1907 -0
- data/vendor/libressl/scripts/i686-w64-mingw32.cmake +9 -0
- data/vendor/libressl/scripts/test +210 -0
- data/vendor/libressl/scripts/wrap-compiler-for-flag-check +31 -0
- data/vendor/libressl/scripts/x86_64-w64-mingw32.cmake +9 -0
- data/vendor/libressl/ssl/CMakeLists.txt +183 -0
- data/vendor/libressl/ssl/Makefile.am +187 -0
- data/vendor/libressl/tests/CMakeLists.txt +970 -0
- data/vendor/libressl/tests/Makefile.am +944 -0
- data/vendor/libressl/tests/aeadtest.sh +30 -0
- data/vendor/libressl/tests/arc4randomforktest.sh +21 -0
- data/vendor/libressl/tests/asn1time_small.test +10 -0
- data/vendor/libressl/tests/cmake/CMakeLists.txt +52 -0
- data/vendor/libressl/tests/cmake/crypto.c +7 -0
- data/vendor/libressl/tests/cmake/ssl.c +6 -0
- data/vendor/libressl/tests/cmake/tls.c +6 -0
- data/vendor/libressl/tests/compat/pipe2.c +186 -0
- data/vendor/libressl/tests/dtlstest.sh +28 -0
- data/vendor/libressl/tests/evptest.sh +22 -0
- data/vendor/libressl/tests/keypairtest.sh +27 -0
- data/vendor/libressl/tests/mlkem_tests.sh +39 -0
- data/vendor/libressl/tests/ocsptest.bat +25 -0
- data/vendor/libressl/tests/ocsptest.sh +23 -0
- data/vendor/libressl/tests/openssl.cnf +29 -0
- data/vendor/libressl/tests/optionstest.c +381 -0
- data/vendor/libressl/tests/pidwraptest.c +85 -0
- data/vendor/libressl/tests/pidwraptest.sh +26 -0
- data/vendor/libressl/tests/quictest.bat +27 -0
- data/vendor/libressl/tests/quictest.sh +30 -0
- data/vendor/libressl/tests/renegotiation_test.bat +27 -0
- data/vendor/libressl/tests/renegotiation_test.sh +30 -0
- data/vendor/libressl/tests/rfc5280time_small.test +10 -0
- data/vendor/libressl/tests/servertest.bat +27 -0
- data/vendor/libressl/tests/servertest.sh +30 -0
- data/vendor/libressl/tests/shutdowntest.bat +27 -0
- data/vendor/libressl/tests/shutdowntest.sh +30 -0
- data/vendor/libressl/tests/ssltest.bat +32 -0
- data/vendor/libressl/tests/ssltest.sh +48 -0
- data/vendor/libressl/tests/testdsa.bat +47 -0
- data/vendor/libressl/tests/testdsa.sh +57 -0
- data/vendor/libressl/tests/testenc.bat +85 -0
- data/vendor/libressl/tests/testenc.sh +93 -0
- data/vendor/libressl/tests/testrsa.bat +47 -0
- data/vendor/libressl/tests/testrsa.sh +57 -0
- data/vendor/libressl/tests/testssl.bat +171 -0
- data/vendor/libressl/tests/tlstest.bat +27 -0
- data/vendor/libressl/tests/tlstest.sh +28 -0
- data/vendor/libressl/tls/CMakeLists.txt +125 -0
- data/vendor/libressl/tls/Makefile.am +76 -0
- data/vendor/libressl/tls/compat/ftruncate.c +17 -0
- data/vendor/libressl/tls/compat/pread.c +29 -0
- data/vendor/libressl/tls/compat/pwrite.c +29 -0
- data/vendor/libressl/update.sh +460 -0
- data/vendor/liburing/.github/workflows/ci.yml +8 -0
- data/vendor/liburing/configure +23 -2
- data/vendor/liburing/examples/helpers.c +1 -1
- data/vendor/liburing/examples/helpers.h +1 -1
- data/vendor/liburing/examples/reg-wait.c +3 -3
- data/vendor/liburing/examples/zcrx.c +5 -5
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/src/include/liburing/io_uring.h +16 -0
- data/vendor/liburing/src/include/liburing.h +20 -4
- data/vendor/liburing/src/lib.h +2 -4
- data/vendor/liburing/src/liburing-ffi.map +7 -0
- data/vendor/liburing/src/liburing.map +7 -0
- data/vendor/liburing/src/register.c +5 -0
- data/vendor/liburing/src/sanitize.c +5 -4
- data/vendor/liburing/src/setup.c +43 -28
- data/vendor/liburing/test/Makefile +7 -0
- data/vendor/liburing/test/cmd-discard.c +2 -2
- data/vendor/liburing/test/evfd-short-read.c +84 -0
- data/vendor/liburing/test/fdinfo-sqpoll.c +117 -0
- data/vendor/liburing/test/fdinfo.c +1 -1
- data/vendor/liburing/test/fixed-buf-merge.c +2 -2
- data/vendor/liburing/test/futex-kill.c +135 -0
- data/vendor/liburing/test/helpers.c +1 -1
- data/vendor/liburing/test/helpers.h +1 -1
- data/vendor/liburing/test/init-mem.c +50 -12
- data/vendor/liburing/test/io_uring_passthrough.c +25 -6
- data/vendor/liburing/test/msg-ring.c +123 -9
- data/vendor/liburing/test/recv-bundle-short-ooo.c +16 -1
- data/vendor/liburing/test/recv-inc-ooo.c +411 -0
- data/vendor/liburing/test/recv-mshot-fair.c +513 -0
- data/vendor/liburing/test/reg-wait.c +14 -14
- data/vendor/liburing/test/send-zerocopy.c +4 -4
- data/vendor/liburing/test/timerfd-short-read.c +81 -0
- data/vendor/liburing/test/timestamp.c +382 -0
- data/vendor/liburing/test/zcrx.c +22 -22
- metadata +222 -2
@@ -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
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* $OpenBSD$ */
|
2
|
+
|
3
|
+
#include <unistd.h>
|
4
|
+
|
5
|
+
#ifdef _WIN32
|
6
|
+
#include <windows.h>
|
7
|
+
#endif
|
8
|
+
|
9
|
+
int
|
10
|
+
getpagesize(void) {
|
11
|
+
#ifdef _WIN32
|
12
|
+
SYSTEM_INFO system_info;
|
13
|
+
GetSystemInfo(&system_info);
|
14
|
+
return system_info.dwPageSize;
|
15
|
+
#else
|
16
|
+
return sysconf(_SC_PAGESIZE);
|
17
|
+
#endif
|
18
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
|
3
|
+
#include <errno.h>
|
4
|
+
|
5
|
+
const char *
|
6
|
+
getprogname(void)
|
7
|
+
{
|
8
|
+
#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
|
9
|
+
/*
|
10
|
+
* Android added getprogname with API 21, so we should not end up here
|
11
|
+
* with APIs newer than 21.
|
12
|
+
* https://github.com/aosp-mirror/platform_bionic/blob/1eb6d3/libc/include/stdlib.h#L160
|
13
|
+
*
|
14
|
+
* Since Android is using portions of OpenBSD libc, it should have
|
15
|
+
* a symbol called __progname.
|
16
|
+
* https://github.com/aosp-mirror/platform_bionic/commit/692207
|
17
|
+
*/
|
18
|
+
extern const char *__progname;
|
19
|
+
return __progname;
|
20
|
+
#else
|
21
|
+
return program_invocation_short_name;
|
22
|
+
#endif
|
23
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
|
3
|
+
#include <windows.h>
|
4
|
+
|
5
|
+
const char *
|
6
|
+
getprogname(void)
|
7
|
+
{
|
8
|
+
static char progname[MAX_PATH + 1];
|
9
|
+
DWORD length = GetModuleFileName(NULL, progname, sizeof (progname) - 1);
|
10
|
+
if (length < 0)
|
11
|
+
return "?";
|
12
|
+
return progname;
|
13
|
+
}
|