]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
unzip: support --version argument
authorMartin Matuska <martin@matuska.de>
Sun, 30 Jul 2023 22:45:57 +0000 (00:45 +0200)
committerMartin Matuska <martin@matuska.de>
Mon, 31 Jul 2023 00:21:42 +0000 (02:21 +0200)
CMakeLists.txt
Makefile.am
build/cmake/config.h.in
configure.ac
unzip/bsdunzip.c
unzip/test/CMakeLists.txt
unzip/test/test.h
unzip/test/test_version.c [new file with mode: 0644]

index 909fef70838e78c4974826e7b5ebfa394839836b..4e2fec82e0d123dbb28f1d7d262064ee0edb16b3 100644 (file)
@@ -65,6 +65,7 @@ SET(VERSION                    "${_major}.${_trimmed_minor}.${_trimmed_revision}
 SET(BSDCPIO_VERSION_STRING     "${VERSION}")
 SET(BSDTAR_VERSION_STRING      "${VERSION}")
 SET(BSDCAT_VERSION_STRING      "${VERSION}")
+SET(BSDUNZIP_VERSION_STRING    "${VERSION}")
 SET(LIBARCHIVE_VERSION_NUMBER  "${_version_number}")
 SET(LIBARCHIVE_VERSION_STRING  "${VERSION}")
 
@@ -695,6 +696,7 @@ int main(void) { return EXT2_IOC_GETFLAGS; }" HAVE_WORKING_EXT2_IOC_GETFLAGS)
 
 LA_CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H)
 LA_CHECK_INCLUDE_FILE("fnmatch.h" HAVE_FNMATCH_H)
+LA_CHECK_INCLUDE_FILE("getopt.h" HAVE_GETOPT_H)
 LA_CHECK_INCLUDE_FILE("grp.h" HAVE_GRP_H)
 LA_CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
 LA_CHECK_INCLUDE_FILE("io.h" HAVE_IO_H)
index e8b676443f1182f8386c241e9d28643af025e999..410659b61bbe2ece7484a54042d8f2615cb2e3e8 100644 (file)
@@ -1510,6 +1510,7 @@ bsdunzip_test_SOURCES= \
        unzip/test/test_q.c \
        unzip/test/test_t.c \
        unzip/test/test_t_bad.c \
+       unzip/test/test_version.c \
        unzip/test/test_x.c \
        unzip/test/test_Z1.c \
        unzip/test/test_P_encryption.c
index daa5e387ae704eb277a4be845d080322573cd288..570afb693bd6cef4d8de0b83143001614b9d3637 100644 (file)
@@ -342,6 +342,9 @@ typedef uint64_t uintmax_t;
 /* Version number of bsdcat */
 #cmakedefine BSDCAT_VERSION_STRING "@BSDCAT_VERSION_STRING@"
 
+/* Version number of bsdunzip */
+#cmakedefine BSDUNZIP_VERSION_STRING "@BSDUNZIP_VERSION_STRING@"
+
 /* Define to 1 if you have the `acl_create_entry' function. */
 #cmakedefine HAVE_ACL_CREATE_ENTRY 1
 
@@ -645,6 +648,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `getline' function. */
 #cmakedefine HAVE_GETLINE 1
 
+/* Define to 1 if you have the <getopt.h> header file. */
+#cmakedefine HAVE_GETOPT_H 1
+
 /* Define to 1 if platform uses `optreset` to reset `getopt` */
 #cmakedefine HAVE_GETOPT_OPTRESET 1
 
index 11aa5e8b2f513cd5de3844df36f9b8e527c9f4f7..8a3aebcef8ec4a90799b27e3ec2f3f871a23a920 100644 (file)
@@ -11,6 +11,7 @@ dnl bsdtar and bsdcpio versioning tracks libarchive
 m4_define([BSDTAR_VERSION_S],LIBARCHIVE_VERSION_S())
 m4_define([BSDCPIO_VERSION_S],LIBARCHIVE_VERSION_S())
 m4_define([BSDCAT_VERSION_S],LIBARCHIVE_VERSION_S())
+m4_define([BSDUNZIP_VERSION_S],LIBARCHIVE_VERSION_S())
 
 AC_PREREQ([2.71])
 
@@ -59,6 +60,8 @@ AC_DEFINE([BSDTAR_VERSION_STRING],"BSDTAR_VERSION_S()",
        [Version number of bsdtar])
 AC_DEFINE([BSDCAT_VERSION_STRING],"BSDTAR_VERSION_S()",
        [Version number of bsdcat])
+AC_DEFINE([BSDUNZIP_VERSION_STRING],"BSDUNZIP_VERSION_S()",
+       [Version number of bsdunzip])
 
 # The shell variables here must be the same as the AC_SUBST() variables
 # below, but the shell variable names apparently cannot be the same as
@@ -66,6 +69,7 @@ AC_DEFINE([BSDCAT_VERSION_STRING],"BSDTAR_VERSION_S()",
 BSDCPIO_VERSION_STRING=BSDCPIO_VERSION_S()
 BSDTAR_VERSION_STRING=BSDTAR_VERSION_S()
 BSDCAT_VERSION_STRING=BSDCAT_VERSION_S()
+BSDUNZIP_VERSION_STRING=BSDUNZIP_VERSION_S()
 LIBARCHIVE_VERSION_STRING=LIBARCHIVE_VERSION_S()
 LIBARCHIVE_VERSION_NUMBER=LIBARCHIVE_VERSION_N()
 
@@ -76,6 +80,7 @@ AC_SUBST(ARCHIVE_LIBTOOL_VERSION)
 AC_SUBST(BSDCPIO_VERSION_STRING)
 AC_SUBST(BSDTAR_VERSION_STRING)
 AC_SUBST(BSDCAT_VERSION_STRING)
+AC_SUBST(BSDUNZIP_VERSION_STRING)
 AC_SUBST(LIBARCHIVE_VERSION_STRING)
 AC_SUBST(LIBARCHIVE_VERSION_NUMBER)
 
@@ -324,7 +329,7 @@ AC_HEADER_DIRENT
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS([acl/libacl.h attr/xattr.h])
 AC_CHECK_HEADERS([copyfile.h ctype.h])
-AC_CHECK_HEADERS([errno.h ext2fs/ext2_fs.h fcntl.h fnmatch.h grp.h])
+AC_CHECK_HEADERS([errno.h ext2fs/ext2_fs.h fcntl.h fnmatch.h getopt.h grp.h])
 
 AC_CACHE_CHECK([whether EXT2_IOC_GETFLAGS is usable],
     [ac_cv_have_decl_EXT2_IOC_GETFLAGS],
index 0b6506a18adc9406fd8e0d1e4a738299fce77d87..83c71a2a9bc6701d328bb45393b1d0a015e559d9 100644 (file)
@@ -59,6 +59,9 @@
 #ifdef HAVE_FNMATCH_H
 #include <fnmatch.h>
 #endif
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
 #ifdef HAVE_STDARG_H
 #include <stdarg.h>
 #endif
@@ -103,6 +106,7 @@ 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;
@@ -1089,17 +1093,34 @@ 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[])
 {
        int opt;
 
+       static struct option longopts[] = {
+           { "version", no_argument, &version_opt, 1 },
+           { 0, 0, 0, 0}
+       };
+
        optind = 1;
 #ifdef HAVE_GETOPT_OPTRESET
        optreset = 1;
 #endif
-       while ((opt = getopt(argc, argv, "aCcd:fI:jLlnO:opP:qtuvx:yZ1")) != -1)
+       while ((opt = getopt_long(argc, argv,
+           "aCcd:fI:jLlnO:opP:qtuvx:yZ1", longopts, NULL)) != -1) {
                switch (opt) {
+               case 0:
+                       break;
                case '1':
                        Z1_opt = 1;
                        break;
@@ -1169,7 +1190,7 @@ getopts(int argc, char *argv[])
                default:
                        usage();
                }
-
+       }
        return (optind);
 }
 
@@ -1179,6 +1200,8 @@ main(int argc, char *argv[])
        const char *zipfile;
        int nopts;
 
+       lafe_setprogname(*argv, "bsdunzip");
+
        if (isatty(STDOUT_FILENO))
                tty = 1;
 
@@ -1199,6 +1222,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.
index bdb3445954f177e4985bf00eeae5f4c0d80dad56..20e730a9cdcab3bedd5643797eeaa6d97c5cef33 100644 (file)
@@ -23,6 +23,7 @@ IF(ENABLE_UNZIP AND ENABLE_TEST)
     test_q.c
     test_t.c
     test_t_bad.c
+    test_version.c
     test_x.c
     test_Z1.c
     test_P_encryption.c
index 8da017f68e165be811b5c4445be066321f96ec63..ba876afd8e240f74639210f2e3739ba97473e381 100644 (file)
@@ -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/unzip/test/test_version.c b/unzip/test/test_version.c
new file mode 100644 (file)
index 0000000..efa7979
--- /dev/null
@@ -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");
+}