From: Ross Lagerwall Date: Mon, 16 Sep 2013 06:39:02 +0000 (+0200) Subject: Show third party library versions in version string X-Git-Tag: v3.1.900a~350^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F49%2Fhead;p=thirdparty%2Flibarchive.git Show third party library versions in version string 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 --- diff --git a/cpio/cpio.c b/cpio/cpio.c index 3889290af..d1784d521 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -500,7 +500,7 @@ version(void) { fprintf(stdout,"bsdcpio %s -- %s\n", BSDCPIO_VERSION_STRING, - archive_version_string()); + archive_version_details()); exit(0); } diff --git a/cpio/test/test.h b/cpio/test/test.h index 666bba0e8..27813e1e5 100644 --- a/cpio/test/test.h +++ b/cpio/test/test.h @@ -66,6 +66,7 @@ #include #include #include +#include #include #ifdef HAVE_UNISTD_H #include diff --git a/cpio/test/test_option_version.c b/cpio/test/test_option_version.c index 7345da1e5..2f2c40901 100644 --- a/cpio/test/test_option_version.c +++ b/cpio/test/test_option_version.c @@ -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); diff --git a/libarchive/archive.h b/libarchive/archive.h index 528144030..23b1ef4fd 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -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; diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c index 0d6140774..637022c8a 100644 --- a/libarchive/archive_util.c +++ b/libarchive/archive_util.c @@ -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 #endif +#ifdef HAVE_ZLIB_H +#include +#endif +#ifdef HAVE_LZMA_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#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) { diff --git a/libarchive/test/main.c b/libarchive/test/main.c index a94fa9251..73caf3c2a 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -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() /* * diff --git a/tar/bsdtar.c b/tar/bsdtar.c index 47267579f..31ceea2aa 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -859,7 +859,7 @@ version(void) { printf("bsdtar %s - %s\n", BSDTAR_VERSION_STRING, - archive_version_string()); + archive_version_details()); exit(0); } diff --git a/tar/test/test.h b/tar/test/test.h index a0a9bb6f6..0ef255f76 100644 --- a/tar/test/test.h +++ b/tar/test/test.h @@ -66,6 +66,7 @@ #include #include #include +#include #include #ifdef HAVE_UNISTD_H #include diff --git a/tar/test/test_version.c b/tar/test/test_version.c index 42472d1bc..5474261d2 100644 --- a/tar/test/test_version.c +++ b/tar/test/test_version.c @@ -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) */