*/
__LA_DECL const char * archive_version_details(void);
+/*
+ * Returns NULL if libarchive was compiled without the associated library.
+ * Otherwise, returns the version number that libarchive was compiled
+ * against.
+ */
+__LA_DECL const char * archive_zlib_version(void);
+__LA_DECL const char * archive_liblzma_version(void);
+__LA_DECL const char * archive_bzlib_version(void);
+__LA_DECL const char * archive_liblz4_version(void);
+
/* Declare our basic types. */
struct archive;
struct archive_entry;
{
static struct archive_string str;
static int init = 0;
+ const char *zlib = archive_zlib_version();
+ const char *liblzma = archive_liblzma_version();
+ const char *bzlib = archive_bzlib_version();
+ const char *liblz4 = archive_liblz4_version();
if (!init) {
archive_string_init(&str);
archive_strcat(&str, ARCHIVE_VERSION_STRING);
-#ifdef HAVE_ZLIB_H
- archive_strcat(&str, " zlib/");
- archive_strcat(&str, ZLIB_VERSION);
-#endif
-#ifdef HAVE_LZMA_H
- archive_strcat(&str, " liblzma/");
- archive_strcat(&str, LZMA_VERSION_STRING);
-#endif
-#ifdef HAVE_BZLIB_H
- {
- const char *p = BZ2_bzlibVersion();
+ if (zlib != NULL) {
+ archive_strcat(&str, " zlib/");
+ archive_strcat(&str, zlib);
+ }
+ if (liblzma) {
+ archive_strcat(&str, " liblzma/");
+ archive_strcat(&str, liblzma);
+ }
+ if (bzlib) {
+ const char *p = bzlib;
const char *sep = strchr(p, ',');
if (sep == NULL)
sep = p + strlen(p);
archive_strcat(&str, " bz2lib/");
archive_strncat(&str, p, sep - p);
}
+ if (liblz4) {
+ archive_strcat(&str, " liblz4/");
+ archive_strcat(&str, liblz4);
+ }
+ }
+ return str.s;
+}
+
+const char *
+archive_zlib_version(void)
+{
+#ifdef HAVE_ZLIB_H
+ return ZLIB_VERSION;
+#else
+ return NULL;
+#endif
+}
+
+const char *
+archive_liblzma_version(void)
+{
+#ifdef HAVE_LZMA_H
+ return LZMA_VERSION_STRING;
+#else
+ return NULL;
#endif
+}
+
+const char *
+archive_bzlib_version(void)
+{
+#ifdef HAVE_BZLIB_H
+ return BZ2_bzlibVersion();
+#else
+ return NULL;
+#endif
+}
+
+const char *
+archive_liblz4_version(void)
+{
#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
- archive_string_sprintf(&str, " liblz4/%d.%d.%d",
- LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, LZ4_VERSION_RELEASE);
+#define NUMBER(x) #x
+ return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
+#undef NUMBER
+#else
+ return NULL;
#endif
- }
- return str.s;
}
int
#include "test.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_compat_zip.c 196962 2009-09-08 05:02:41Z kientzle $");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
/* Copy this function for each test file and adjust it accordingly. */
DEFINE_TEST(test_compat_zip_1)
{
/* Read second entry. */
r = archive_read_next_header(a, &ae);
- if (r == ARCHIVE_FATAL && !libz_enabled) {
+ if (r == ARCHIVE_FATAL && archive_zlib_version() == NULL) {
skipping("Skipping ZIP compression check: %s",
archive_error_string(a));
goto finish;
/* Extract under a different name. */
archive_entry_set_pathname(ae, "test_3.txt");
- if(libz_enabled) {
+ if(archive_zlib_version() != NULL) {
char *p;
size_t s;
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
#include "test.h"
__FBSDID("$FreeBSD");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
/*
Execute the following command to rebuild the data for this program:
tail -n +44 test_read_format_cab.c | /bin/sh
assertEqualInt(33000, archive_entry_size(ae));
for (s = 0; s + sizeof(buff) < 33000; s+= sizeof(buff)) {
ssize_t rsize = archive_read_data(a, buff, sizeof(buff));
- if (comp == MSZIP && rsize == ARCHIVE_FATAL && !libz_enabled) {
+ if (comp == MSZIP && rsize == ARCHIVE_FATAL && archive_zlib_version() == NULL) {
skipping("Skipping CAB format(MSZIP) check: %s",
archive_error_string(a));
goto finish;
char buff[128];
char zero[128];
- if (comp == MSZIP && !libz_enabled) {
+ if (comp == MSZIP && archive_zlib_version() == NULL) {
skipping("Skipping CAB format(MSZIP) check for %s",
refname);
return;
#include "test.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_zip.c 189482 2009-03-07 03:30:35Z kientzle $");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
/*
* The reference file for this has been manually tweaked so that:
* * file2 has length-at-end but file1 does not
assertEqualInt(archive_entry_is_encrypted(ae), 0);
assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
failure("archive_read_data() returns number of bytes read");
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(18, archive_read_data(a, buff, 19));
assertEqualMem(buff, "hello\nhello\nhello\n", 18);
} else {
}
assert(archive_entry_size_is_set(ae));
assertEqualInt(18, archive_entry_size(ae));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
failure("file2 has a bad CRC, so read should fail and not change buff");
memset(buff, 'a', 19);
assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19));
failure("zip reader should read Info-ZIP New Unix Extra Field");
assertEqualInt(1001, archive_entry_uid(ae));
assertEqualInt(1001, archive_entry_gid(ae));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
failure("archive_read_data() returns number of bytes read");
assertEqualInt(18, archive_read_data(a, buff, 19));
assertEqualMem(buff, "hello\nhello\nhello\n", 18);
assertEqualInt(0, archive_entry_size(ae));
}
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
assertFileContents("hello\x0A", 6, "hello.txt");
} else {
#include "test.h"
__FBSDID("$FreeBSD$");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
/*
* Read a zip file that has a zip comment in the end of the central
* directory record.
assertEqualIntA(a, ARCHIVE_OK, archive_read_set_option(a, "zip", "mac-ext", "1"));
assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualIntA(a, ARCHIVE_OK,
archive_read_next_header(a, &ae));
} else {
assertEqualString("file3", archive_entry_pathname(ae));
assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
failure("Mac metadata should be set");
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
const void *metadata;
if (assert((metadata = archive_entry_mac_metadata(ae, &s))
!= NULL)) {
#include "test.h"
__FBSDID("$FreeBSD$");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
DEFINE_TEST(test_read_format_zip_traditional_encryption_data)
{
/* This file is password protected (Traditional PKWARE Enctypted).
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED,
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED,
#include "test.h"
__FBSDID("$FreeBSD$");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
static void
test_winzip_aes(const char *refname, int need_libz)
{
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (!need_libz || libz_enabled) {
+ if (!need_libz || archive_zlib_version() != NULL) {
assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19));
#include "test.h"
__FBSDID("$FreeBSD$");
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
{
const char *refname = "test_read_format_zip_winzip_aes256_large.zip";
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED,
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED,
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED,
assertEqualInt(1, archive_entry_is_data_encrypted(ae));
assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
- if (libz_enabled) {
+ if (archive_zlib_version() != NULL) {
assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
} else {
assertEqualInt(ARCHIVE_FAILED,
assert((a = archive_write_new()) != NULL);
r = archive_write_add_filter_lz4(a);
- if (r != ARCHIVE_OK) {
- if (canLz4() && r == ARCHIVE_WARN)
- use_prog = 1;
- else {
+ if (archive_liblz4_version() == NULL) {
+ if (!canLz4()) {
skipping("lz4 writing not supported on this platform");
+ assertEqualInt(ARCHIVE_WARN, r);
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
return;
+ } else {
+ assertEqualInt(ARCHIVE_WARN, r);
+ use_prog = 1;
}
+ } else {
+ assertEqualInt(ARCHIVE_OK, r);
}
buffsize = 2000000;
assert((a = archive_write_new()) != NULL);
r = archive_write_add_filter_lz4(a);
- if (r != ARCHIVE_OK) {
- if (canLz4() && r == ARCHIVE_WARN)
- use_prog = 1;
- else {
+ if (archive_liblz4_version() == NULL) {
+ if (!canLz4()) {
skipping("lz4 writing not supported on this platform");
+ assertEqualInt(ARCHIVE_WARN, r);
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
return;
+ } else {
+ assertEqualInt(ARCHIVE_WARN, r);
+ use_prog = 1;
}
+ } else {
+ assertEqualInt(ARCHIVE_OK, r);
}
buffsize = 2000000;