4000724620b87f8fb985325af339568f01e7c8de
[wimlib] / src / compat.c
1 /* TODO: Deprecated stuff to delete when shared library version is bumped up  */
2
3 #include "wimlib.h"
4 #include "wimlib/compiler.h"
5
6 WIMLIBAPI int
7 wimlib_lzx_set_default_params(const struct wimlib_lzx_params_old *params)
8 {
9         return wimlib_set_default_compressor_params(WIMLIB_COMPRESSION_TYPE_LZX,
10                                                     (const struct wimlib_compressor_params_header*)params);
11 }
12
13 WIMLIBAPI int
14 wimlib_lzx_alloc_context(const struct wimlib_lzx_params_old *params,
15                          struct wimlib_lzx_context_old **ctx_pp)
16 {
17         wimlib_lzx_free_context(*ctx_pp);
18         *ctx_pp = NULL;
19         return wimlib_create_compressor(WIMLIB_COMPRESSION_TYPE_LZX,
20                                         32768,
21                                         (const struct wimlib_compressor_params_header*)params,
22                                         (struct wimlib_compressor**)ctx_pp);
23 }
24
25 WIMLIBAPI void
26 wimlib_lzx_free_context(struct wimlib_lzx_context_old *ctx)
27 {
28         wimlib_free_compressor((struct wimlib_compressor*)ctx);
29 }
30
31 WIMLIBAPI unsigned
32 wimlib_lzx_compress2(const void *udata, unsigned ulen, void *cdata,
33                      struct wimlib_lzx_context_old *ctx)
34 {
35         return wimlib_compress(udata, ulen, cdata, ulen - 1,
36                                (struct wimlib_compressor*)ctx);
37 }
38
39 static unsigned
40 do_compress(const void *udata, unsigned ulen, void *cdata, int ctype)
41 {
42         struct wimlib_compressor *c;
43         unsigned clen;
44
45         if (wimlib_create_compressor(ctype, 32768, NULL, &c))
46                 return 0;
47         clen = wimlib_compress(udata, ulen, cdata, ulen - 1, c);
48         wimlib_free_compressor(c);
49         return clen;
50 }
51
52 WIMLIBAPI unsigned
53 wimlib_lzx_compress(const void *udata, unsigned ulen, void *cdata)
54 {
55         return do_compress(udata, ulen, cdata, WIMLIB_COMPRESSION_TYPE_LZX);
56 }
57
58 WIMLIBAPI unsigned
59 wimlib_xpress_compress(const void *udata, unsigned ulen, void *cdata)
60 {
61         return do_compress(udata, ulen, cdata, WIMLIB_COMPRESSION_TYPE_XPRESS);
62 }
63
64 static int
65 do_decompress(const void *cdata, unsigned clen,
66               void *udata, unsigned ulen, int ctype)
67 {
68         int ret;
69         struct wimlib_decompressor *dec;
70
71         if (wimlib_create_decompressor(ctype, 32768, NULL, &dec))
72                 return -1;
73         ret = wimlib_decompress(cdata, clen, udata, ulen, dec);
74         wimlib_free_decompressor(dec);
75         return ret;
76 }
77
78 WIMLIBAPI int
79 wimlib_lzx_decompress(const void *cdata, unsigned clen,
80                       void *udata, unsigned ulen)
81 {
82         return do_decompress(cdata, clen, udata, ulen, WIMLIB_COMPRESSION_TYPE_LZX);
83 }
84
85
86 WIMLIBAPI int
87 wimlib_xpress_decompress(const void *cdata, unsigned clen,
88                          void *udata, unsigned ulen)
89 {
90         return do_decompress(cdata, clen, udata, ulen, WIMLIB_COMPRESSION_TYPE_XPRESS);
91 }