]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Show third party library versions in version string 49/head
authorRoss Lagerwall <rosslagerwall@gmail.com>
Mon, 16 Sep 2013 06:39:02 +0000 (08:39 +0200)
committerRoss Lagerwall <rosslagerwall@gmail.com>
Mon, 16 Sep 2013 06:39:02 +0000 (08:39 +0200)
Add a utility function, archive_version_details, to return a string
containing the libarchive version as well as the versions of third party
libraries such as zlib, bz2lib and liblzma.  Use this function for
bsdtar --version and bsdcpio --version.

http://code.google.com/p/libarchive/issues/detail?id=118

cpio/cpio.c
cpio/test/test.h
cpio/test/test_option_version.c
libarchive/archive.h
libarchive/archive_util.c
libarchive/test/main.c
tar/bsdtar.c
tar/test/test.h
tar/test/test_version.c

index 3889290afc53b92baaedcc59a8749313d4950442..d1784d52195f6e84015ef2350547e987f7df23d4 100644 (file)
@@ -500,7 +500,7 @@ version(void)
 {
        fprintf(stdout,"bsdcpio %s -- %s\n",
            BSDCPIO_VERSION_STRING,
-           archive_version_string());
+           archive_version_details());
        exit(0);
 }
 
index 666bba0e8b303b277f977f10286ee19b150cc613..27813e1e52300aa99d26c69a252047deebb25ecd 100644 (file)
@@ -66,6 +66,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
index 7345da1e5157923ce29ee69609c18e014555158f..2f2c409017005da1ee498c7a31d7008308c2b59e 100644 (file)
@@ -74,6 +74,11 @@ verify(const char *p, size_t s)
        /* Skip a single trailing a,b,c, or d. */
        if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
                ++q;
+       /* Skip arbitrary third-party version numbers. */
+       while (s > 0 && (*q == ' ' || *q == '/' || *q == '.' || isalnum(*q))) {
+               ++q;
+               --s;
+       }
        /* All terminated by end-of-line: \r, \r\n, or \n */
        assert(s >= 1);
        failure("Version: %s", p);
index 5281440306caa9669963daf3708f1c9222e26e46..23b1ef4fd01cd410b93f6f7be579c50e004ea64a 100644 (file)
@@ -133,6 +133,11 @@ __LA_DECL int              archive_version_number(void);
 #define        ARCHIVE_VERSION_STRING "libarchive 3.1.2"
 __LA_DECL const char * archive_version_string(void);
 
+/*
+ * Detailed textual name/version of the library and its dependencies.
+ */
+__LA_DECL const char * archive_version_details(void);
+
 /* Declare our basic types. */
 struct archive;
 struct archive_entry;
index 0d6140774d2666311cf339419f78d31339f3c567..637022c8abf32728b7d9af7d054bb8affa42224f 100644 (file)
@@ -45,6 +45,15 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:1
 #if defined(HAVE_WINCRYPT_H) && !defined(__CYGWIN__)
 #include <wincrypt.h>
 #endif
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#endif
+#ifdef HAVE_LZMA_H
+#include <lzma.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <bzlib.h>
+#endif
 
 #include "archive.h"
 #include "archive_private.h"
@@ -76,6 +85,33 @@ archive_version_string(void)
        return (ARCHIVE_VERSION_STRING);
 }
 
+const char *
+archive_version_details(void)
+{
+       static char version[80];
+#ifdef HAVE_BZLIB_H
+       char *bzlib_version = strdup(BZ2_bzlibVersion());
+       char *ptr = strchr(bzlib_version, ',');
+       if (ptr)
+               *ptr = '\0';
+#endif
+       snprintf(version, sizeof(version), ARCHIVE_VERSION_STRING
+#ifdef HAVE_ZLIB_H
+               " zlib/" ZLIB_VERSION
+#endif
+#ifdef HAVE_LZMA_H
+               " liblzma/" LZMA_VERSION_STRING
+#endif
+#ifdef HAVE_BZLIB_H
+               " bz2lib/%s", bzlib_version
+#endif
+               );
+#ifdef HAVE_BZLIB_H
+       free(bzlib_version);
+#endif
+       return (version);
+}
+
 int
 archive_errno(struct archive *a)
 {
index a94fa9251a717725607862098b010ea563e5f44e..73caf3c2a822f87aa025cddeff63ec2180684f6c 100644 (file)
@@ -67,7 +67,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/test/main.c 201247 2009-12-30 05:59:21Z
 #define        LIBRARY "libarchive"
 #define        EXTRA_DUMP(x)   archive_error_string((struct archive *)(x))
 #define        EXTRA_ERRNO(x)  archive_errno((struct archive *)(x))
-#define        EXTRA_VERSION   archive_version_string()
+#define        EXTRA_VERSION   archive_version_details()
 
 /*
  *
index 47267579f0c4d0747785cc610121b1fd7d7654b9..31ceea2aa9ebf009706a883f6adff9096c1d46b4 100644 (file)
@@ -859,7 +859,7 @@ version(void)
 {
        printf("bsdtar %s - %s\n",
            BSDTAR_VERSION_STRING,
-           archive_version_string());
+           archive_version_details());
        exit(0);
 }
 
index a0a9bb6f600c284262f3f83af75596a89fa40bae..0ef255f76f0a4c9ddf124d78ca36566ca13e25b7 100644 (file)
@@ -66,6 +66,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
index 42472d1bc264c2650265a74ff6593564b52747d0..5474261d207af0d2f7f1ae87738577c32e1dfa7b 100644 (file)
@@ -87,6 +87,11 @@ DEFINE_TEST(test_version)
        /* Skip a single trailing a,b,c, or d. */
        if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
                ++q;
+       /* Skip arbitrary third-party version numbers. */
+       while (s > 0 && (*q == ' ' || *q == '/' || *q == '.' || isalnum(*q))) {
+               ++q;
+               --s;
+       }
        /* All terminated by end-of-line. */
        assert(s >= 1);
        /* Skip an optional CR character (e.g., Windows) */