chiark / gitweb /
man,journal: add note about sd_journal_get_cutoff_monotonic_usec return value
[elogind.git] / src / journal / compress.c
index 49d694ac28273f751f909c3bbf7dfe17bf3eb6e4..ee18bc8fbc7928b6c3ef3e5572ab037d14365e92 100644 (file)
@@ -49,6 +49,13 @@ DEFINE_STRING_TABLE_LOOKUP(object_compressed, int);
 
 int compress_blob_xz(const void *src, uint64_t src_size, void *dst, uint64_t *dst_size) {
 #ifdef HAVE_XZ
+        static const lzma_options_lzma opt = {
+                1u << 20u, NULL, 0, LZMA_LC_DEFAULT, LZMA_LP_DEFAULT,
+                LZMA_PB_DEFAULT, LZMA_MODE_FAST, 128, LZMA_MF_HC3, 4};
+        static const lzma_filter filters[2] = {
+                {LZMA_FILTER_LZMA2, (lzma_options_lzma*) &opt},
+                {LZMA_VLI_UNKNOWN, NULL}
+        };
         lzma_ret ret;
         size_t out_pos = 0;
 
@@ -60,8 +67,11 @@ int compress_blob_xz(const void *src, uint64_t src_size, void *dst, uint64_t *ds
         /* Returns < 0 if we couldn't compress the data or the
          * compressed result is longer than the original */
 
-        ret = lzma_easy_buffer_encode(LZMA_PRESET_DEFAULT, LZMA_CHECK_NONE, NULL,
-                                      src, src_size, dst, &out_pos, src_size - 1);
+        if (src_size < 80)
+                return -ENOBUFS;
+
+        ret = lzma_stream_buffer_encode((lzma_filter*) filters, LZMA_CHECK_NONE, NULL,
+                                        src, src_size, dst, &out_pos, src_size - 1);
         if (ret != LZMA_OK)
                 return -ENOBUFS;
 
@@ -122,7 +132,7 @@ int decompress_blob_xz(const void *src, uint64_t src_size,
 
         space = MIN(src_size * 2, dst_max ?: (uint64_t) -1);
         if (!greedy_realloc(dst, dst_alloc_size, space, 1))
-                return false;
+                return -ENOMEM;
 
         s.next_in = src;
         s.avail_in = src_size;
@@ -148,7 +158,7 @@ int decompress_blob_xz(const void *src, uint64_t src_size,
                 used = space - s.avail_out;
                 space = MIN(2 * space, dst_max ?: (uint64_t) -1);
                 if (!greedy_realloc(dst, dst_alloc_size, space, 1))
-                        return false;
+                        return -ENOMEM;
 
                 s.avail_out = space - used;
                 s.next_out = *dst + used;
@@ -333,6 +343,7 @@ int decompress_startswith(int compression,
 }
 
 int compress_stream_xz(int fdf, int fdt, off_t max_bytes) {
+#ifdef HAVE_XZ
         _cleanup_(lzma_end) lzma_stream s = LZMA_STREAM_INIT;
         lzma_ret ret;
 
@@ -404,6 +415,9 @@ int compress_stream_xz(int fdf, int fdt, off_t max_bytes) {
                         }
                 }
         }
+#else
+        return -EPROTONOSUPPORT;
+#endif
 }
 
 #define LZ4_BUFSIZE (512*1024)