From nobody Sat May 04 12:37:36 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VWnJ05l01z5KVQ1; Sat, 4 May 2024 12:37:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VWnJ02dklz44HQ; Sat, 4 May 2024 12:37:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714826256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1FKJphqn3VhfcMEI6o/sP/t3A1rgiKBDEEMVdNxu+DI=; b=rvOB2kahidaA0Au7EDWh+rSb9/t7NqPRRWnrCaFQKsPzSWqBgh7SBYGB3CpYUcrNLH61Zv JNj2yirE7eF0geQSc9fjcD25WYLFezAK9tV7Fvb9Wuijg+Pv+WCTobYEZHAagQkM6GJQC6 ePbL7g2X5nfeoWKrcjlDS4d+NX8ZM3FqERu+2vGPsB+OolUC5XQFB7MHw7gYNu2sorUxtk gSR8ILYSYIu0wftiyzRQkmQS8WezECB2PQN+qrAyJjKrA+BJZie1aQmZo2+DscvLbhB+8k y5adxEelaVQx1M4Mrt0pZphp/iQPBTWL+5fHVyLbVGVOPkupeLrgH3M8Z3vRgw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714826256; a=rsa-sha256; cv=none; b=lPChTg7vO1RnOh3pWzwk9DEwXcU1nVFTrhiXEJ1CGfYdKednOAkR4LKtLo3RwFlk9xQ+VE /qptqEAtfpmKJMbnlRjq4LpO4m4jkiOEqKN+AHku/ONnL4Pcjo5ryngFazwpEPjk+hdPHb 9+MZY68Ra2N/HtrrGLHgNtwt62q8Et7YM6kEb3g1kpBlks8lXJ/A2q9IzU4Wwxc48kqhKU 8lr2Ek6J9VEh0lsUFe0OP++DTqG+WKjuAabHVU2suG5ErSaTp3gt/LIkOAk1d7eLV8T0CR R0sW6Sft4EuiVWwM02KaYTRDglNWDw74DvCX693OE8btZ3S83ypBhilpEFrhxQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714826256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1FKJphqn3VhfcMEI6o/sP/t3A1rgiKBDEEMVdNxu+DI=; b=IhIHeq2TFQDp0Qh1vbsNMtFBwyFt7JwXhhE2SmGWkWmfgg5om/CReE4bNbHcJfZI7CDGNy dqBcHeSISL1EOZzoTcc33929rm5ypFODNbkQJ7Q/HBBvhiCe7ClfTYsTHO1tl1cWIcRDIQ wpVDqrmDTiwcwzwVowROZ7NCSFTwzPdZcRGnB9570yL7WYHl2IzLhz8imh63bfW6lgSOkd 3e+v44JvWepSLPHP8bNkYdjpSvwLDlwEAHnyasmlRFJGBAFBB6BNdC4QiBWuSqwghJrbgP dw2gO+NYSbBdwrUrOfnQaf1htUMjOZEtqlAARvv9jf/rykit+pxqWC8ZwTiv4Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VWnJ02FM4zVPD; Sat, 4 May 2024 12:37:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 444Cbad8072372; Sat, 4 May 2024 12:37:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 444Cba2c072369; Sat, 4 May 2024 12:37:36 GMT (envelope-from git) Date: Sat, 4 May 2024 12:37:36 GMT Message-Id: <202405041237.444Cba2c072369@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Martin Matuska Subject: git: 0db84579ce20 - stable/13 - libarchive: merge from vendor branch List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mm X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0db84579ce2024b674062d961f1e3e26a253ffdd Auto-Submitted: auto-generated The branch stable/13 has been updated by mm: URL: https://cgit.FreeBSD.org/src/commit/?id=0db84579ce2024b674062d961f1e3e26a253ffdd commit 0db84579ce2024b674062d961f1e3e26a253ffdd Author: Martin Matuska AuthorDate: 2023-07-31 11:13:30 +0000 Commit: Martin Matuska CommitDate: 2024-05-04 11:53:07 +0000 libarchive: merge from vendor branch Changes to not yet connected unzip only. (cherry picked from commit d91bfe0fb7faab2e1f0b8e160b0cf59afb8576c4) --- contrib/libarchive/cat/cmdline.c | 12 +- contrib/libarchive/unzip/bsdunzip.c | 66 +++++-- contrib/libarchive/unzip/bsdunzip.h | 63 +++++++ contrib/libarchive/unzip/cmdline.c | 250 +++++++++++++++++++++++++++ contrib/libarchive/unzip/test/test.h | 2 +- contrib/libarchive/unzip/test/test_version.c | 34 ++++ 6 files changed, 402 insertions(+), 25 deletions(-) diff --git a/contrib/libarchive/cat/cmdline.c b/contrib/libarchive/cat/cmdline.c index cae19beb7d4c..3c4b7a8c4b9e 100644 --- a/contrib/libarchive/cat/cmdline.c +++ b/contrib/libarchive/cat/cmdline.c @@ -24,7 +24,7 @@ */ /* - * Command line parser for tar. + * Command line parser for bsdcat. */ #include "bsdcat_platform.h" @@ -44,12 +44,12 @@ __FBSDID("$FreeBSD$"); #include "err.h" /* - * Short options for tar. Please keep this sorted. + * Short options for bsdcat. Please keep this sorted. */ static const char *short_options = "h"; /* - * Long options for tar. Please keep this list sorted. + * Long options for bsdcat. Please keep this list sorted. * * The symbolic names for options that lack a short equivalent are * defined in bsdcat.h. Also note that so far I've found no need @@ -61,7 +61,7 @@ static const struct bsdcat_option { const char *name; int required; /* 1 if this option requires an argument. */ int equivalent; /* Equivalent short option. */ -} tar_longopts[] = { +} bsdcat_longopts[] = { { "help", 0, 'h' }, { "version", 0, OPTION_VERSION }, { NULL, 0, 0 } @@ -90,7 +90,7 @@ static const struct bsdcat_option { * -W long options: There's an obscure GNU convention (only rarely * supported even there) that allows "-W option=argument" as an * alternative way to support long options. This was supported in - * early bsdcat as a way to access long options on platforms that did + * early bsdtar as a way to access long options on platforms that did * not support getopt_long() and is preserved here for backwards * compatibility. (Of course, if I'd started with a custom * command-line parser from the beginning, I would have had normal @@ -223,7 +223,7 @@ bsdcat_getopt(struct bsdcat *bsdcat) } /* Search the table for an unambiguous match. */ - for (popt = tar_longopts; popt->name != NULL; popt++) { + for (popt = bsdcat_longopts; popt->name != NULL; popt++) { /* Short-circuit if first chars don't match. */ if (popt->name[0] != bsdcat->getopt_word[0]) continue; diff --git a/contrib/libarchive/unzip/bsdunzip.c b/contrib/libarchive/unzip/bsdunzip.c index 0b6506a18adc..b8f6ff4bbf95 100644 --- a/contrib/libarchive/unzip/bsdunzip.c +++ b/contrib/libarchive/unzip/bsdunzip.c @@ -79,8 +79,7 @@ #endif #endif -#include -#include +#include "bsdunzip.h" #include "passphrase.h" #include "err.h" @@ -90,19 +89,20 @@ static int C_opt; /* match case-insensitively */ static int c_opt; /* extract to stdout */ static const char *d_arg; /* directory */ static int f_opt; /* update existing files only */ -static char *O_arg; /* encoding */ +static const char *O_arg; /* encoding */ static int j_opt; /* junk directories */ static int L_opt; /* lowercase names */ static int n_opt; /* never overwrite */ static int o_opt; /* always overwrite */ static int p_opt; /* extract to stdout, quiet */ -static char *P_arg; /* passphrase */ +static const char *P_arg; /* passphrase */ static int q_opt; /* quiet */ static int t_opt; /* test */ static int u_opt; /* update */ static int v_opt; /* verbose/list */ static const char *y_str = ""; /* 4 digit year */ static int Z1_opt; /* zipinfo mode list files only */ +static int version_opt; /* version string */ /* debug flag */ static int unzip_debug; @@ -113,6 +113,8 @@ static int zipinfo_mode; /* running on tty? */ static int tty; +int bsdunzip_optind; + /* convenience macro */ /* XXX should differentiate between ARCHIVE_{WARN,FAIL,RETRY} */ #define ac(call) \ @@ -1089,20 +1091,30 @@ usage(void) exit(EXIT_FAILURE); } +static void +version(void) +{ + printf("bsdunzip %s - %s \n", + BSDUNZIP_VERSION_STRING, + archive_version_details()); + exit(0); +} + static int getopts(int argc, char *argv[]) { + struct bsdunzip *bsdunzip, bsdunzip_storage; int opt; + bsdunzip_optind = 1; - optind = 1; -#ifdef HAVE_GETOPT_OPTRESET - optreset = 1; -#endif - while ((opt = getopt(argc, argv, "aCcd:fI:jLlnO:opP:qtuvx:yZ1")) != -1) + bsdunzip = &bsdunzip_storage; + memset(bsdunzip, 0, sizeof(*bsdunzip)); + + bsdunzip->argv = argv; + bsdunzip->argc = argc; + + while ((opt = bsdunzip_getopt(bsdunzip)) != -1) { switch (opt) { - case '1': - Z1_opt = 1; - break; case 'a': a_opt = 1; break; @@ -1113,14 +1125,14 @@ getopts(int argc, char *argv[]) c_opt = 1; break; case 'd': - d_arg = optarg; + d_arg = bsdunzip->argument; break; case 'f': f_opt = 1; break; case 'I': case 'O': - O_arg = optarg; + O_arg = bsdunzip->argument; break; case 'j': j_opt = 1; @@ -1143,7 +1155,7 @@ getopts(int argc, char *argv[]) p_opt = 1; break; case 'P': - P_arg = optarg; + P_arg = bsdunzip->argument; break; case 'q': q_opt = 1; @@ -1158,19 +1170,30 @@ getopts(int argc, char *argv[]) v_opt = 2; break; case 'x': - add_pattern(&exclude, optarg); + add_pattern(&exclude, bsdunzip->argument); break; case 'y': y_str = " "; break; case 'Z': zipinfo_mode = 1; + if (bsdunzip->argument != NULL && + strcmp(bsdunzip->argument, "1") == 0) { + Z1_opt = 1; + } + break; + case OPTION_VERSION: + version_opt = 1; + break; + case OPTION_NONE: break; default: usage(); } - - return (optind); + if (opt == OPTION_NONE) + break; + } + return (bsdunzip_optind); } int @@ -1179,6 +1202,8 @@ main(int argc, char *argv[]) const char *zipfile; int nopts; + lafe_setprogname(*argv, "bsdunzip"); + if (isatty(STDOUT_FILENO)) tty = 1; @@ -1199,6 +1224,11 @@ main(int argc, char *argv[]) */ nopts = getopts(argc, argv); + if (version_opt == 1) { + version(); + exit(EXIT_SUCCESS); + } + /* * When more of the zipinfo mode options are implemented, this * will need to change. diff --git a/contrib/libarchive/unzip/bsdunzip.h b/contrib/libarchive/unzip/bsdunzip.h new file mode 100644 index 000000000000..12b65cefb466 --- /dev/null +++ b/contrib/libarchive/unzip/bsdunzip.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2023, Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BSDUNZIP_H_INCLUDED +#define BSDUNZIP_H_INCLUDED + +#if defined(PLATFORM_CONFIG_H) +/* Use hand-built config.h in environments that need it. */ +#include PLATFORM_CONFIG_H +#else +/* Not having a config.h of some sort is a serious problem. */ +#include "config.h" +#endif + +#include +#include + +struct bsdunzip { + /* Option parser state */ + int getopt_state; + char *getopt_word; + + /* Miscellaneous state information */ + int argc; + char **argv; + const char *argument; +}; + +struct bsdunzip_getopt_ret { + int index; + int opt; +}; + +enum { + OPTION_NONE, + OPTION_VERSION +}; + +int bsdunzip_getopt(struct bsdunzip *); + +#endif diff --git a/contrib/libarchive/unzip/cmdline.c b/contrib/libarchive/unzip/cmdline.c new file mode 100644 index 000000000000..95d4f99b8242 --- /dev/null +++ b/contrib/libarchive/unzip/cmdline.c @@ -0,0 +1,250 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Command line parser for bsdunzip. + */ + +#include "bsdunzip_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "bsdunzip.h" +#include "err.h" + +extern int bsdunzip_optind; + +/* + * Short options for bsdunzip. Please keep this sorted. + */ +static const char *short_options + = "aCcd:fI:jLlnO:opP:qtuvx:yZ:"; + +/* + * Long options for bsdunzip. Please keep this list sorted. + * + * The symbolic names for options that lack a short equivalent are + * defined in bsdunzip.h. Also note that so far I've found no need + * to support optional arguments to long options. That would be + * a small change to the code below. + */ + +static const struct bsdunzip_option { + const char *name; + int required; /* 1 if this option requires an argument. */ + int equivalent; /* Equivalent short option. */ +} bsdunzip_longopts[] = { + { "version", 0, OPTION_VERSION }, + { NULL, 0, 0 } +}; + +/* + * This getopt implementation has two key features that common + * getopt_long() implementations lack. Apart from those, it's a + * straightforward option parser, considerably simplified by not + * needing to support the wealth of exotic getopt_long() features. It + * has, of course, been shamelessly tailored for bsdunzip. (If you're + * looking for a generic getopt_long() implementation for your + * project, I recommend Gregory Pietsch's public domain getopt_long() + * implementation.) The two additional features are: + */ + +int +bsdunzip_getopt(struct bsdunzip *bsdunzip) +{ + enum { state_start = 0, state_next_word, state_short, state_long }; + + const struct bsdunzip_option *popt, *match = NULL, *match2 = NULL; + const char *p, *long_prefix = "--"; + size_t optlength; + int opt = OPTION_NONE; + int required = 0; + + bsdunzip->argument = NULL; + + /* First time through, initialize everything. */ + if (bsdunzip->getopt_state == state_start) { + /* Skip program name. */ + ++bsdunzip->argv; + --bsdunzip->argc; + if (*bsdunzip->argv == NULL) + return (-1); + bsdunzip->getopt_state = state_next_word; + } + + /* + * We're ready to look at the next word in argv. + */ + if (bsdunzip->getopt_state == state_next_word) { + /* No more arguments, so no more options. */ + if (bsdunzip->argv[0] == NULL) + return (-1); + /* Doesn't start with '-', so no more options. */ + if (bsdunzip->argv[0][0] != '-') + return (-1); + /* "--" marks end of options; consume it and return. */ + if (strcmp(bsdunzip->argv[0], "--") == 0) { + ++bsdunzip->argv; + --bsdunzip->argc; + return (-1); + } + /* Get next word for parsing. */ + bsdunzip->getopt_word = *bsdunzip->argv++; + --bsdunzip->argc; + bsdunzip_optind++; + if (bsdunzip->getopt_word[1] == '-') { + /* Set up long option parser. */ + bsdunzip->getopt_state = state_long; + bsdunzip->getopt_word += 2; /* Skip leading '--' */ + } else { + /* Set up short option parser. */ + bsdunzip->getopt_state = state_short; + ++bsdunzip->getopt_word; /* Skip leading '-' */ + } + } + + /* + * We're parsing a group of POSIX-style single-character options. + */ + if (bsdunzip->getopt_state == state_short) { + /* Peel next option off of a group of short options. */ + opt = *bsdunzip->getopt_word++; + if (opt == '\0') { + /* End of this group; recurse to get next option. */ + bsdunzip->getopt_state = state_next_word; + return bsdunzip_getopt(bsdunzip); + } + + /* Does this option take an argument? */ + p = strchr(short_options, opt); + if (p == NULL) + return ('?'); + if (p[1] == ':') + required = 1; + + /* If it takes an argument, parse that. */ + if (required) { + /* If arg is run-in, bsdunzip->getopt_word already points to it. */ + if (bsdunzip->getopt_word[0] == '\0') { + /* Otherwise, pick up the next word. */ + bsdunzip->getopt_word = *bsdunzip->argv; + if (bsdunzip->getopt_word == NULL) { + lafe_warnc(0, + "Option -%c requires an argument", + opt); + return ('?'); + } + ++bsdunzip->argv; + --bsdunzip->argc; + bsdunzip_optind++; + } + bsdunzip->getopt_state = state_next_word; + bsdunzip->argument = bsdunzip->getopt_word; + } + } + + /* We're reading a long option */ + if (bsdunzip->getopt_state == state_long) { + /* After this long option, we'll be starting a new word. */ + bsdunzip->getopt_state = state_next_word; + + /* Option name ends at '=' if there is one. */ + p = strchr(bsdunzip->getopt_word, '='); + if (p != NULL) { + optlength = (size_t)(p - bsdunzip->getopt_word); + bsdunzip->argument = (char *)(uintptr_t)(p + 1); + } else { + optlength = strlen(bsdunzip->getopt_word); + } + + /* Search the table for an unambiguous match. */ + for (popt = bsdunzip_longopts; popt->name != NULL; popt++) { + /* Short-circuit if first chars don't match. */ + if (popt->name[0] != bsdunzip->getopt_word[0]) + continue; + /* If option is a prefix of name in table, record it.*/ + if (strncmp(bsdunzip->getopt_word, popt->name, optlength) == 0) { + match2 = match; /* Record up to two matches. */ + match = popt; + /* If it's an exact match, we're done. */ + if (strlen(popt->name) == optlength) { + match2 = NULL; /* Forget the others. */ + break; + } + } + } + + /* Fail if there wasn't a unique match. */ + if (match == NULL) { + lafe_warnc(0, + "Option %s%s is not supported", + long_prefix, bsdunzip->getopt_word); + return ('?'); + } + if (match2 != NULL) { + lafe_warnc(0, + "Ambiguous option %s%s (matches --%s and --%s)", + long_prefix, bsdunzip->getopt_word, match->name, match2->name); + return ('?'); + } + + /* We've found a unique match; does it need an argument? */ + if (match->required) { + /* Argument required: get next word if necessary. */ + if (bsdunzip->argument == NULL) { + bsdunzip->argument = *bsdunzip->argv; + if (bsdunzip->argument == NULL) { + lafe_warnc(0, + "Option %s%s requires an argument", + long_prefix, match->name); + return ('?'); + } + ++bsdunzip->argv; + --bsdunzip->argc; + bsdunzip_optind++; + } + } else { + /* Argument forbidden: fail if there is one. */ + if (bsdunzip->argument != NULL) { + lafe_warnc(0, + "Option %s%s does not allow an argument", + long_prefix, match->name); + return ('?'); + } + } + return (match->equivalent); + } + + return (opt); +} diff --git a/contrib/libarchive/unzip/test/test.h b/contrib/libarchive/unzip/test/test.h index 8da017f68e16..ba876afd8e24 100644 --- a/contrib/libarchive/unzip/test/test.h +++ b/contrib/libarchive/unzip/test/test.h @@ -35,6 +35,6 @@ #undef EXTRA_DUMP /* How to dump extra data */ #undef EXTRA_ERRNO /* How to dump errno */ /* How to generate extra version info. */ -#define EXTRA_VERSION (systemf("%s -v", testprog) ? "" : "") +#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") #include "test_common.h" diff --git a/contrib/libarchive/unzip/test/test_version.c b/contrib/libarchive/unzip/test/test_version.c new file mode 100644 index 000000000000..efa797982d57 --- /dev/null +++ b/contrib/libarchive/unzip/test/test_version.c @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2003-2017 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" + +/* + * Test that --version option works and generates reasonable output. + */ + +DEFINE_TEST(test_version) +{ + assertVersion(testprog, "bsdunzip"); +}