blob: 8714a387a7f0bc0948a5d322efbc610ba19e5218 [file] [log] [blame]
Lasse Collinbcc4b362009-03-22 13:12:47 +02001/*
2 * Test application to test buffer-to-buffer decoding
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#include <stdbool.h>
11#include <stdio.h>
12#include <string.h>
13#include "xz.h"
14
15#define BUFFER_SIZE (1024 * 1024)
16
17static uint8_t in[BUFFER_SIZE];
18static uint8_t out[BUFFER_SIZE];
19
20int main(void)
21{
22 struct xz_buf b;
23 struct xz_dec *s;
24 enum xz_ret ret;
25
26 xz_crc32_init();
27
Lasse Collinc4c6f5c2010-06-09 12:22:35 +030028 s = xz_dec_init(XZ_SINGLE, 0);
Lasse Collinbcc4b362009-03-22 13:12:47 +020029 if (s == NULL) {
Du Huanpenge75f4eb2015-11-03 08:29:27 +080030 fputs("Initialization failed\n", stderr);
Lasse Collinbcc4b362009-03-22 13:12:47 +020031 return 1;
32 }
33
34 b.in = in;
35 b.in_pos = 0;
36 b.in_size = fread(in, 1, sizeof(in), stdin);
Du Huanpenge75f4eb2015-11-03 08:29:27 +080037
Lasse Collinbcc4b362009-03-22 13:12:47 +020038 b.out = out;
39 b.out_pos = 0;
40 b.out_size = sizeof(out);
41
42 ret = xz_dec_run(s, &b);
43 xz_dec_end(s);
44
45 fwrite(out, 1, b.out_pos, stdout);
46 fprintf(stderr, "%d\n", ret);
47
48 return 0;
49}