aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-17 13:09:06 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-17 13:10:25 +0200
commitb52a9567520570bd6c850bcad3a6966f68639ef7 (patch)
treeb63e6515b25020b3abdfdd63731db0d44ac54925
parentec38f4fa90d65362002a901b2d74be09fc6b128c (diff)
Add a check whether libzstd supports stream compression
Streaming compression was added fairly recently to zstd (and then the API was changed a few times). Rather than rely on libzstd versioning macros, this commit adds an m4 script to test at configure time if the enums/functions we need are available by trying to compile a small sample. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--configure.ac2
-rw-r--r--lib/fstream/compress/ostream_compressor.c2
-rw-r--r--lib/fstream/compress/zstd.c2
-rw-r--r--lib/fstream/compressor.c2
-rw-r--r--lib/fstream/uncompress/istream_compressor.c2
-rw-r--r--lib/fstream/uncompress/zstd.c2
-rw-r--r--m4/zstd.m411
7 files changed, 20 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 3de1109..70a1dfd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -182,6 +182,8 @@ AS_IF([test "x$with_zstd" != "xno"], [
[with_zstd="no"])])
], [])
+AS_IF([test "x$with_zstd" != "xno"], [AC_TEST_ZSTD_STREAM], [])
+
AS_IF([test "x$with_selinux" != "xno"], [
have_selinux="yes"
diff --git a/lib/fstream/compress/ostream_compressor.c b/lib/fstream/compress/ostream_compressor.c
index 7ea7919..30ff7eb 100644
--- a/lib/fstream/compress/ostream_compressor.c
+++ b/lib/fstream/compress/ostream_compressor.c
@@ -78,7 +78,7 @@ ostream_t *ostream_compressor_create(ostream_t *strm, int comp_id)
#endif
break;
case FSTREAM_COMPRESSOR_ZSTD:
-#ifdef WITH_ZSTD
+#if defined(WITH_ZSTD) && defined(HAVE_ZSTD_STREAM)
comp = ostream_zstd_create(strm->get_filename(strm));
#endif
break;
diff --git a/lib/fstream/compress/zstd.c b/lib/fstream/compress/zstd.c
index f4f7f86..c0b002e 100644
--- a/lib/fstream/compress/zstd.c
+++ b/lib/fstream/compress/zstd.c
@@ -8,6 +8,7 @@
#include <zstd.h>
+#ifdef HAVE_ZSTD_STREAM
typedef struct {
ostream_comp_t base;
@@ -90,3 +91,4 @@ ostream_comp_t *ostream_zstd_create(const char *filename)
base->cleanup = cleanup;
return base;
}
+#endif /* HAVE_ZSTD_STREAM */
diff --git a/lib/fstream/compressor.c b/lib/fstream/compressor.c
index 903a5f7..48f9567 100644
--- a/lib/fstream/compressor.c
+++ b/lib/fstream/compressor.c
@@ -51,7 +51,7 @@ bool fstream_compressor_exists(int id)
case FSTREAM_COMPRESSOR_XZ:
return true;
#endif
-#ifdef WITH_ZSTD
+#if defined(WITH_ZSTD) && defined(HAVE_ZSTD_STREAM)
case FSTREAM_COMPRESSOR_ZSTD:
return true;
#endif
diff --git a/lib/fstream/uncompress/istream_compressor.c b/lib/fstream/uncompress/istream_compressor.c
index bc8ef39..75edd1b 100644
--- a/lib/fstream/uncompress/istream_compressor.c
+++ b/lib/fstream/uncompress/istream_compressor.c
@@ -40,7 +40,7 @@ istream_t *istream_compressor_create(istream_t *strm, int comp_id)
#endif
break;
case FSTREAM_COMPRESSOR_ZSTD:
-#ifdef WITH_ZSTD
+#if defined(WITH_ZSTD) && defined(HAVE_ZSTD_STREAM)
comp = istream_zstd_create(strm->get_filename(strm));
#endif
break;
diff --git a/lib/fstream/uncompress/zstd.c b/lib/fstream/uncompress/zstd.c
index 1838af5..fd22cbf 100644
--- a/lib/fstream/uncompress/zstd.c
+++ b/lib/fstream/uncompress/zstd.c
@@ -8,6 +8,7 @@
#include <zstd.h>
+#ifdef HAVE_ZSTD_STREAM
typedef struct {
istream_comp_t base;
@@ -77,3 +78,4 @@ istream_comp_t *istream_zstd_create(const char *filename)
base->cleanup = cleanup;
return base;
}
+#endif /* HAVE_ZSTD_STREAM */
diff --git a/m4/zstd.m4 b/m4/zstd.m4
new file mode 100644
index 0000000..f644264
--- /dev/null
+++ b/m4/zstd.m4
@@ -0,0 +1,11 @@
+AC_DEFUN([AC_TEST_ZSTD_STREAM], [
+ AC_MSG_CHECKING([whether zstd supports stream compression])
+ AC_LANG_PUSH([C])
+ ac_zstd_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $ZSTD_CFLAGS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <zstd.h>], [ZSTD_EndDirective op = ZSTD_e_end; ZSTD_compressStream2(NULL, NULL, NULL, op);])],
+ AC_DEFINE(HAVE_ZSTD_STREAM, 1, [Does zstd support stream compression?])
+ AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]))
+ CFLAGS=$ac_zstd_save_CFLAGS
+ AC_LANG_POP([C])
+])