aboutsummaryrefslogtreecommitdiff
path: root/lib/libarchive
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@FreeBSD.org>2008-03-14 22:31:57 +0000
committerTim Kientzle <kientzle@FreeBSD.org>2008-03-14 22:31:57 +0000
commit42d1f7b4bab0036b25eba3d93e7f37c361fc38e9 (patch)
treeed7a21dbba4563b3af9187e2b437ef359e0068b1 /lib/libarchive
parent0349d719b10afbdfb1f9d06ab4a2cd7216fb286b (diff)
downloadsrc-42d1f7b4bab0036b25eba3d93e7f37c361fc38e9.tar.gz
src-42d1f7b4bab0036b25eba3d93e7f37c361fc38e9.zip
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.
Notes
Notes: svn path=/head/; revision=177187
Diffstat (limited to 'lib/libarchive')
-rw-r--r--lib/libarchive/archive_util.c46
-rw-r--r--lib/libarchive/test/test_archive_api_feature.c14
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
}