From 474ea5abd8ad2fd82dfdc8707cab3058ca4dd365 Mon Sep 17 00:00:00 2001 From: kientzle Date: Fri, 14 Mar 2008 22:31:57 +0000 Subject: [PATCH] Rework the versioning implementation and test to match the new interface. Mark the functions that are going away in libarchive 3.0. In particular, archive_version_string() now computes the string rather than assuming that it will be created by the build infrastructure. Eventually, this will allow some simplification of the build infrastructure. --- lib/libarchive/archive_util.c | 46 ++++++++++++++++++- .../test/test_archive_api_feature.c | 14 ++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/libarchive/archive_util.c b/lib/libarchive/archive_util.c index e80cabb642db..cad14f4b810b 100644 --- a/lib/libarchive/archive_util.c +++ b/lib/libarchive/archive_util.c @@ -38,29 +38,71 @@ __FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_private.h" +#include "archive_string.h" +#if ARCHIVE_VERSION_NUMBER < 3000000 +/* These disappear in libarchive 3.0 */ +/* Deprecated. */ int archive_api_feature(void) { return (ARCHIVE_API_FEATURE); } +/* Deprecated. */ int archive_api_version(void) { return (ARCHIVE_API_VERSION); } +/* Deprecated synonym for archive_version_number() */ int archive_version_stamp(void) { - return (ARCHIVE_VERSION_STAMP); + return (archive_version_number()); } +/* Deprecated synonym for archive_version_string() */ const char * archive_version(void) { - return (ARCHIVE_LIBRARY_VERSION); + return (archive_version_string()); +} +#endif + +int +archive_version_number(void) +{ + return (ARCHIVE_VERSION_NUMBER); +} + +/* + * Format a version string of the form "libarchive x.y.z", where x, y, + * z are the correct parts of the version ID from + * archive_version_number(). + * + * I used to do all of this at build time in shell scripts but that + * proved to be a portability headache. + */ + +const char * +archive_version_string(void) +{ + static char buff[128]; + struct archive_string as; + int n; + + if (buff[0] == '\0') { + n = archive_version_number(); + memset(&as, 0, sizeof(as)); + archive_string_sprintf(&as, "libarchive %d.%d.%d", + n / 1000000, (n / 1000) % 1000, n % 1000); + strncpy(buff, as.s, sizeof(buff)); + buff[sizeof(buff) - 1] = '\0'; + archive_string_free(&as); + } + return (buff); } int diff --git a/lib/libarchive/test/test_archive_api_feature.c b/lib/libarchive/test/test_archive_api_feature.c index 32a51fba2d12..ba9dd4485847 100644 --- a/lib/libarchive/test/test_archive_api_feature.c +++ b/lib/libarchive/test/test_archive_api_feature.c @@ -27,6 +27,19 @@ __FBSDID("$FreeBSD$"); DEFINE_TEST(test_archive_api_feature) { + char buff[128]; + + /* This is the (hopefully) final versioning API. */ + assertEqualInt(ARCHIVE_VERSION_NUMBER, archive_version_number()); + sprintf(buff, "libarchive %d.%d.%d", + archive_version_number() / 1000000, + (archive_version_number() / 1000) % 1000, + archive_version_number() % 1000); + assertEqualString(buff, archive_version_string()); + +/* This is all scheduled to disappear in libarchive 3.0 */ +#if ARCHIVE_VERSION_NUMBER < 3000000 + assertEqualInt(ARCHIVE_VERSION_STAMP, ARCHIVE_VERSION_NUMBER); assertEqualInt(ARCHIVE_API_FEATURE, archive_api_feature()); assertEqualInt(ARCHIVE_API_VERSION, archive_api_version()); /* @@ -48,4 +61,5 @@ DEFINE_TEST(test_archive_api_feature) skipping("archive_version_stamp()"); #endif assertEqualString(ARCHIVE_LIBRARY_VERSION, archive_version()); +#endif }