]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Break out the library version functions into a separate source file.
authorTim Kientzle <kientzle@acm.org>
Sat, 11 Mar 2017 23:30:38 +0000 (15:30 -0800)
committerTim Kientzle <kientzle@acm.org>
Sat, 11 Mar 2017 23:30:38 +0000 (15:30 -0800)
This breaks a static dependency on libbz2.  Before this,
any use of libarchive that ended up linking archive_util.c would
require libbz2.  (And since archive_util.c contains a bunch of
very core functions, this is pretty much everybody.)
Now you only require libbz2 if you request library version information
or actually use some other feature that involves bzip2 support.

Note that most of the libraries provide version information via
compile-time macros -- libbz2 only provides such information via
a function call, which is why this issue only arises with libbz2.
In particular, the libbz2 version reports the version that we
are currently linked against; the other library versions report
the version we were compiled with (which may not be the same as
what we are currently using).

Makefile.am
libarchive/CMakeLists.txt
libarchive/archive_util.c
libarchive/archive_version_details.c [new file with mode: 0644]

index b5a41f980fbd5f4230618fbf382050130becd746..8c573a9f8f27f72616b79fd2c498ab19735543ae 100644 (file)
@@ -186,6 +186,7 @@ libarchive_la_SOURCES= \
        libarchive/archive_string_composition.h \
        libarchive/archive_string_sprintf.c \
        libarchive/archive_util.c \
+       libarchive/archive_version_details.c \
        libarchive/archive_virtual.c \
        libarchive/archive_write.c \
        libarchive/archive_write_disk_acl.c \
index 1f85c014586497683bdf4254a8adac7b5596d684..d55fa2d81f0a4f5f295070b3ce8fc3bcef6fed40 100644 (file)
@@ -106,6 +106,7 @@ SET(libarchive_SOURCES
   archive_string_composition.h
   archive_string_sprintf.c
   archive_util.c
+  archive_version_details.c
   archive_virtual.c
   archive_write.c
   archive_write_disk_acl.c
index 6b3bd61163d9a4794350986e04e1fc2af1269c85..a751868f4542ac474915146bc37d27a56799024f 100644 (file)
@@ -89,88 +89,6 @@ archive_version_string(void)
        return (ARCHIVE_VERSION_STRING);
 }
 
-const char *
-archive_version_details(void)
-{
-       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);
-               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)
-#define str(s) #s
-#define NUMBER(x) str(x)
-       return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
-#undef NUMBER
-#undef str
-#else
-       return NULL;
-#endif
-}
-
 int
 archive_errno(struct archive *a)
 {
diff --git a/libarchive/archive_version_details.c b/libarchive/archive_version_details.c
new file mode 100644 (file)
index 0000000..813f0f3
--- /dev/null
@@ -0,0 +1,133 @@
+/*-
+ * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $");
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#endif
+#ifdef HAVE_LZMA_H
+#include <lzma.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <bzlib.h>
+#endif
+#ifdef HAVE_LZ4_H
+#include <lz4.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+#include "archive_string.h"
+
+const char *
+archive_version_details(void)
+{
+       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);
+               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)
+#define str(s) #s
+#define NUMBER(x) str(x)
+       return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
+#undef NUMBER
+#undef str
+#else
+       return NULL;
+#endif
+}