1 #include <assert.h>
2 #include <libdeflate.h>
3 #include <string.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <sys/stat.h>
7 
main(int argc,char ** argv)8 int main(int argc, char **argv)
9 {
10 	struct libdeflate_decompressor *d;
11 	struct libdeflate_compressor *c;
12 	int ret;
13 	int fd = open(argv[1], O_RDONLY);
14 	struct stat stbuf;
15 	assert(fd >= 0);
16 	ret = fstat(fd, &stbuf);
17 	assert(!ret);
18 
19 	char in[stbuf.st_size];
20 	ret = read(fd, in, sizeof in);
21 	assert(ret == sizeof in);
22 
23 	c = libdeflate_alloc_compressor(6);
24 	d = libdeflate_alloc_decompressor();
25 
26 	char out[sizeof(in)];
27 	char checkarray[sizeof(in)];
28 
29 	size_t csize = libdeflate_deflate_compress(c, in,sizeof in, out, sizeof out);
30 	if (csize) {
31 		enum libdeflate_result res;
32 		res = libdeflate_deflate_decompress(d, out, csize, checkarray, sizeof in, NULL);
33 		assert(!res);
34 		assert(!memcmp(in, checkarray, sizeof in));
35 	}
36 
37 	libdeflate_free_compressor(c);
38 	libdeflate_free_decompressor(d);
39 	return 0;
40 }
41