aboutsummaryrefslogtreecommitdiffstats
path: root/userspace
diff options
context:
space:
mode:
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile4
-rw-r--r--userspace/boottest.c3
-rw-r--r--userspace/bytetest.c135
-rw-r--r--userspace/xz_config.h17
-rw-r--r--userspace/xzminidec.c3
5 files changed, 159 insertions, 3 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 9d1779905bd2..5bd6b282e252 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -10,11 +10,11 @@
CC = gcc -std=gnu89
BCJ_CPPFLAGS = -DXZ_DEC_X86 -DXZ_DEC_POWERPC -DXZ_DEC_IA64 \
-DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_SPARC
-CPPFLAGS = -DXZ_DEC_ANY_CHECK
+CPPFLAGS = -DXZ_USE_CRC64 -DXZ_DEC_ANY_CHECK
CFLAGS = -ggdb3 -O2 -pedantic -Wall -Wextra
RM = rm -f
VPATH = ../linux/include/linux ../linux/lib/xz
-COMMON_SRCS = xz_crc32.c xz_dec_stream.c xz_dec_lzma2.c xz_dec_bcj.c
+COMMON_SRCS = xz_crc32.c xz_crc64.c xz_dec_stream.c xz_dec_lzma2.c xz_dec_bcj.c
COMMON_OBJS = $(COMMON_SRCS:.c=.o)
XZMINIDEC_OBJS = xzminidec.o
BYTETEST_OBJS = bytetest.o
diff --git a/userspace/boottest.c b/userspace/boottest.c
index f5bc28261ea6..1aef5ed69d11 100644
--- a/userspace/boottest.c
+++ b/userspace/boottest.c
@@ -19,6 +19,9 @@ static void error(/*const*/ char *msg)
fprintf(stderr, "%s\n", msg);
}
+/* Disable the CRC64 support even if it was enabled in the Makefile. */
+#undef XZ_USE_CRC64
+
#include "../linux/lib/decompress_unxz.c"
static uint8_t in[1024 * 1024];
diff --git a/userspace/bytetest.c b/userspace/bytetest.c
new file mode 100644
index 000000000000..aa48b9b3edce
--- /dev/null
+++ b/userspace/bytetest.c
@@ -0,0 +1,135 @@
+/*
+ * Lazy test for the case when the output size is known
+ *
+ * Author: Lasse Collin <lasse.collin@tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "xz.h"
+
+static uint8_t in[1];
+static uint8_t out[BUFSIZ];
+
+int main(int argc, char **argv)
+{
+ struct xz_buf b;
+ struct xz_dec *s;
+ enum xz_ret ret;
+ const char *msg;
+ size_t uncomp_size;
+
+ if (argc != 2) {
+ fputs("Give uncompressed size as the argument", stderr);
+ return 1;
+ }
+
+ uncomp_size = atoi(argv[1]);
+
+ xz_crc32_init();
+
+ /*
+ * Support up to 64 MiB dictionary. The actually needed memory
+ * is allocated once the headers have been parsed.
+ */
+ s = xz_dec_init(XZ_DYNALLOC, 1 << 26);
+ if (s == NULL) {
+ msg = "Memory allocation failed\n";
+ goto error;
+ }
+
+ b.in = in;
+ b.in_pos = 0;
+ b.in_size = 0;
+ b.out = out;
+ b.out_pos = 0;
+ b.out_size = uncomp_size < BUFSIZ ? uncomp_size : BUFSIZ;
+
+ while (true) {
+ if (b.in_pos == b.in_size) {
+ b.in_size = fread(in, 1, sizeof(in), stdin);
+ b.in_pos = 0;
+ }
+
+ ret = xz_dec_run(s, &b);
+
+ if (b.out_pos == sizeof(out)) {
+ if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
+ msg = "Write error\n";
+ goto error;
+ }
+
+ uncomp_size -= b.out_pos;
+ b.out_pos = 0;
+ b.out_size = uncomp_size < BUFSIZ
+ ? uncomp_size : BUFSIZ;
+ }
+
+ if (ret == XZ_OK)
+ continue;
+
+#ifdef XZ_DEC_ANY_CHECK
+ if (ret == XZ_UNSUPPORTED_CHECK) {
+ fputs(argv[0], stderr);
+ fputs(": ", stderr);
+ fputs("Unsupported check; not verifying "
+ "file integrity\n", stderr);
+ continue;
+ }
+#endif
+
+ if (uncomp_size != b.out_pos) {
+ msg = "Uncompressed size doesn't match\n";
+ goto error;
+ }
+
+ if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos
+ || fclose(stdout)) {
+ msg = "Write error\n";
+ goto error;
+ }
+
+ switch (ret) {
+ case XZ_STREAM_END:
+ xz_dec_end(s);
+ return 0;
+
+ case XZ_MEM_ERROR:
+ msg = "Memory allocation failed\n";
+ goto error;
+
+ case XZ_MEMLIMIT_ERROR:
+ msg = "Memory usage limit reached\n";
+ goto error;
+
+ case XZ_FORMAT_ERROR:
+ msg = "Not a .xz file\n";
+ goto error;
+
+ case XZ_OPTIONS_ERROR:
+ msg = "Unsupported options in the .xz headers\n";
+ goto error;
+
+ case XZ_DATA_ERROR:
+ case XZ_BUF_ERROR:
+ msg = "File is corrupt\n";
+ goto error;
+
+ default:
+ msg = "Bug!\n";
+ goto error;
+ }
+ }
+
+error:
+ xz_dec_end(s);
+ fputs(argv[0], stderr);
+ fputs(": ", stderr);
+ fputs(msg, stderr);
+ return 1;
+}
diff --git a/userspace/xz_config.h b/userspace/xz_config.h
index 71bb0293fe3d..eb9dac1a4bda 100644
--- a/userspace/xz_config.h
+++ b/userspace/xz_config.h
@@ -10,6 +10,9 @@
#ifndef XZ_CONFIG_H
#define XZ_CONFIG_H
+/* Uncomment to enable CRC64 support. */
+/* #define XZ_USE_CRC64 */
+
/* Uncomment as needed to enable BCJ filter decoders. */
/* #define XZ_DEC_X86 */
/* #define XZ_DEC_POWERPC */
@@ -18,7 +21,19 @@
/* #define XZ_DEC_ARMTHUMB */
/* #define XZ_DEC_SPARC */
-#include <stdbool.h>
+/*
+ * MSVC doesn't support modern C but XZ Embedded is mostly C89
+ * so these are enough.
+ */
+#ifdef _MSC_VER
+typedef unsigned char bool;
+# define true 1
+# define false 0
+# define inline __inline
+#else
+# include <stdbool.h>
+#endif
+
#include <stdlib.h>
#include <string.h>
diff --git a/userspace/xzminidec.c b/userspace/xzminidec.c
index 2a039c6dea10..ba07413125a1 100644
--- a/userspace/xzminidec.c
+++ b/userspace/xzminidec.c
@@ -37,6 +37,9 @@ int main(int argc, char **argv)
}
xz_crc32_init();
+#ifdef XZ_USE_CRC64
+ xz_crc64_init();
+#endif
/*
* Support up to 64 MiB dictionary. The actually needed memory