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.
This commit is contained in:
parent
495bb86033
commit
474ea5abd8
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user