MFC r177185,r177186,r177187: Rework the versioning interface again.
The new interface has fewer elements and seems to be easier to use. Of course, I'm retaining the old interface until libarchive 3.x.
This commit is contained in:
parent
36f1982ea4
commit
a9793940df
@ -28,12 +28,6 @@
|
||||
#ifndef ARCHIVE_H_INCLUDED
|
||||
#define ARCHIVE_H_INCLUDED
|
||||
|
||||
/*
|
||||
* This header file corresponds to:
|
||||
* Library version @ARCHIVE_VERSION@
|
||||
* Shared library version @SHLIB_MAJOR@
|
||||
*/
|
||||
|
||||
#include <sys/types.h> /* Linux requires this for off_t */
|
||||
@ARCHIVE_H_INCLUDE_INTTYPES_H@
|
||||
#include <stdio.h> /* For FILE * */
|
||||
@ -51,58 +45,59 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Each of the version identifiers comes as a macro and a function.
|
||||
* The version number is provided as both a macro and a function.
|
||||
* The macro identifies the installed header; the function identifies
|
||||
* the library version (which may not be the same if you're using a
|
||||
* dynamically-linked version of the library).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Textual name/version of the library, useful for version displays.
|
||||
*/
|
||||
#define ARCHIVE_LIBRARY_VERSION "libarchive @LIBARCHIVE_VERSION_STRING@"
|
||||
const char * archive_version(void);
|
||||
|
||||
/*
|
||||
* The "version stamp" is a single integer that makes it easy to check
|
||||
* the exact version: for version a.b.c, the version stamp is
|
||||
* printf("%d%03d%03d",a,b,c). For example, version 2.12.108 has
|
||||
* version stamp 2012108.
|
||||
* The version number is expressed as a single integer that makes it
|
||||
* easy to compare versions at build time: for version a.b.c, the
|
||||
* version number is printf("%d%03d%03d",a,b,c). For example, if you
|
||||
* know your application requires version 2.12.108 or later, you can
|
||||
* assert that ARCHIVE_VERSION >= 2012108.
|
||||
*
|
||||
* This was introduced with libarchive 1.9.0 in the libarchive 1.x family
|
||||
* and libarchive 2.2.4 in the libarchive 2.x family. The following
|
||||
* may be useful if you really want to do feature detection for earlier
|
||||
* libarchive versions (which defined API_VERSION and API_FEATURE):
|
||||
* This single-number format was introduced with libarchive 1.9.0 in
|
||||
* the libarchive 1.x family and libarchive 2.2.4 in the libarchive
|
||||
* 2.x family. The following may be useful if you really want to do
|
||||
* feature detection for earlier libarchive versions (which defined
|
||||
* ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead):
|
||||
*
|
||||
* #ifndef ARCHIVE_VERSION_STAMP
|
||||
* #define ARCHIVE_VERSION_STAMP \
|
||||
* #ifndef ARCHIVE_VERSION_NUMBER
|
||||
* #define ARCHIVE_VERSION_NUMBER \
|
||||
* (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000)
|
||||
* #endif
|
||||
*/
|
||||
#define ARCHIVE_VERSION_STAMP @LIBARCHIVE_VERSION@
|
||||
#define ARCHIVE_VERSION_NUMBER @LIBARCHIVE_VERSION@
|
||||
int archive_version_number(void);
|
||||
|
||||
/*
|
||||
* Textual name/version of the library, useful for version displays.
|
||||
*/
|
||||
const char * archive_version_string(void);
|
||||
|
||||
#if ARCHIVE_VERSION_NUMBER < 3000000
|
||||
/*
|
||||
* Deprecated; these are older names that will be removed in favor of
|
||||
* the simpler definitions above.
|
||||
*/
|
||||
#define ARCHIVE_VERSION_STAMP ARCHIVE_VERSION_NUMBER
|
||||
int archive_version_stamp(void);
|
||||
|
||||
/*
|
||||
* Major version number: If ARCHIVE_API_VERSION !=
|
||||
* archive_api_version(), then the library you were linked with is
|
||||
* using an incompatible API to the one you were compiled with. This
|
||||
* is almost certainly a fatal problem.
|
||||
* This is deprecated and will be removed; use ARCHIVE_VERSION_STAMP
|
||||
* instead.
|
||||
*/
|
||||
#define ARCHIVE_API_VERSION (ARCHIVE_VERSION_STAMP / 1000000)
|
||||
#define ARCHIVE_LIBRARY_VERSION "libarchive @LIBARCHIVE_VERSION_STRING@"
|
||||
const char * archive_version(void);
|
||||
#define ARCHIVE_API_VERSION (ARCHIVE_VERSION_NUMBER / 1000000)
|
||||
int archive_api_version(void);
|
||||
|
||||
/*
|
||||
* Minor version number. This is deprecated and will be removed.
|
||||
* Use ARCHIVE_VERSION_STAMP to adapt to libarchive API variations.
|
||||
*/
|
||||
#define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_STAMP / 1000) % 1000)
|
||||
#define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_NUMBER / 1000) % 1000)
|
||||
int archive_api_feature(void);
|
||||
#endif
|
||||
|
||||
|
||||
#if ARCHIVE_VERSION_NUMBER < 3000000
|
||||
/* This should never have been here in the first place. */
|
||||
/* Legacy of old tar assumptions, will be removed in libarchive 3.0. */
|
||||
#define ARCHIVE_BYTES_PER_RECORD 512
|
||||
#define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240
|
||||
#endif
|
||||
|
||||
/* Declare our basic types. */
|
||||
struct archive;
|
||||
@ -119,6 +114,7 @@ struct archive_entry;
|
||||
#define ARCHIVE_WARN (-20) /* Partial success. */
|
||||
/* For example, if write_header "fails", then you can't push data. */
|
||||
#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */
|
||||
/* But if write_header is "fatal," then this archive is dead and useless. */
|
||||
#define ARCHIVE_FATAL (-30) /* No more operations are possible. */
|
||||
|
||||
/*
|
||||
@ -146,7 +142,7 @@ struct archive_entry;
|
||||
typedef ssize_t archive_read_callback(struct archive *, void *_client_data,
|
||||
const void **_buffer);
|
||||
/* Skips at most request bytes from archive and returns the skipped amount */
|
||||
#if ARCHIVE_API_VERSION < 2
|
||||
#if ARCHIVE_VERSION_NUMBER < 2000000
|
||||
typedef ssize_t archive_skip_callback(struct archive *, void *_client_data,
|
||||
size_t request);
|
||||
#else
|
||||
@ -370,7 +366,7 @@ void archive_read_extract_set_skip_file(struct archive *,
|
||||
int archive_read_close(struct archive *);
|
||||
/* Release all resources and destroy the object. */
|
||||
/* Note that archive_read_finish will call archive_read_close for you. */
|
||||
#if ARCHIVE_API_VERSION > 1
|
||||
#if ARCHIVE_VERSION_NUMBER >= 2000000
|
||||
int archive_read_finish(struct archive *);
|
||||
#else
|
||||
/* Temporarily allow library to compile with either 1.x or 2.0 API. */
|
||||
@ -446,7 +442,7 @@ int archive_write_open_memory(struct archive *,
|
||||
*/
|
||||
int archive_write_header(struct archive *,
|
||||
struct archive_entry *);
|
||||
#if ARCHIVE_API_VERSION > 1
|
||||
#if ARCHIVE_VERSION_NUMBER >= 2000000
|
||||
ssize_t archive_write_data(struct archive *, const void *, size_t);
|
||||
#else
|
||||
/* Temporarily allow library to compile with either 1.x or 2.0 API. */
|
||||
@ -456,7 +452,7 @@ int archive_write_data(struct archive *, const void *, size_t);
|
||||
ssize_t archive_write_data_block(struct archive *, const void *, size_t, off_t);
|
||||
int archive_write_finish_entry(struct archive *);
|
||||
int archive_write_close(struct archive *);
|
||||
#if ARCHIVE_API_VERSION > 1
|
||||
#if ARCHIVE_VERSION_NUMBER >= 2000000
|
||||
int archive_write_finish(struct archive *);
|
||||
#else
|
||||
/* Temporarily allow library to compile with either 1.x or 2.0 API. */
|
||||
|
@ -116,4 +116,7 @@ void __archive_string_vsprintf(struct archive_string *, const char *,
|
||||
va_list);
|
||||
#define archive_string_vsprintf __archive_string_vsprintf
|
||||
|
||||
void __archive_string_sprintf(struct archive_string *, const char *, ...);
|
||||
#define archive_string_sprintf __archive_string_sprintf
|
||||
|
||||
#endif
|
||||
|
@ -44,6 +44,16 @@ __FBSDID("$FreeBSD$");
|
||||
#include "archive_string.h"
|
||||
#include "archive_private.h"
|
||||
|
||||
void
|
||||
__archive_string_sprintf(struct archive_string *as, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
archive_string_vsprintf(as, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like 'vsprintf', but ensures the target is big enough, resizing if
|
||||
* necessary.
|
||||
|
@ -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…
x
Reference in New Issue
Block a user