]>
git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/zmod.h
c5216a8fd3e9c2aa00ea2eb7e9d4d750cfd68b44
4 #include <linux/zlib.h>
6 /* NOTE: z_compress_level/z_uncompress are nearly identical copies of
7 * the compress2/uncompress functions provided by the official zlib
8 * package available at http://zlib.net/. The only changes made we to
9 * slightly adapt the functioned called to match the linux kernel
10 * implementation of zlib.
13 /* ===========================================================================
14 * Compresses the source buffer into the destination buffer. The level
15 * parameter has the same meaning as in deflateInit. sourceLen is the byte
16 * length of the source buffer. Upon entry, destLen is the total size of the
17 * destination buffer, which must be at least 0.1% larger than sourceLen plus
18 * 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
20 * compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
21 * memory, Z_BUF_ERROR if there was not enough room in the output buffer,
22 * Z_STREAM_ERROR if the level parameter is invalid.
25 z_compress_level(Byte
*dest
, uLong
*destLen
, const Byte
*source
,
26 uLong sourceLen
, int level
)
31 stream
.next_in
= (Byte
*)source
;
32 stream
.avail_in
= (uInt
)sourceLen
;
34 /* Check for source > 64K on 16-bit machine: */
35 if ((uLong
)stream
.avail_in
!= sourceLen
)
38 stream
.next_out
= dest
;
39 stream
.avail_out
= (uInt
)*destLen
;
41 if ((uLong
)stream
.avail_out
!= *destLen
)
44 err
= zlib_deflateInit(&stream
, level
);
48 err
= zlib_deflate(&stream
, Z_FINISH
);
49 if (err
!= Z_STREAM_END
) {
50 zlib_deflateEnd(&stream
);
51 return err
== Z_OK
? Z_BUF_ERROR
: err
;
53 *destLen
= stream
.total_out
;
55 err
= zlib_deflateEnd(&stream
);
57 } /* z_compress_level() */
59 /* ===========================================================================
60 * Decompresses the source buffer into the destination buffer. sourceLen is
61 * the byte length of the source buffer. Upon entry, destLen is the total
62 * size of the destination buffer, which must be large enough to hold the
63 * entire uncompressed data. (The size of the uncompressed data must have
64 * been saved previously by the compressor and transmitted to the decompressor
65 * by some mechanism outside the scope of this compression library.)
66 * Upon exit, destLen is the actual size of the compressed buffer.
67 * This function can be used to decompress a whole file at once if the
68 * input file is mmap'ed.
70 * uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
71 * enough memory, Z_BUF_ERROR if there was not enough room in the output
72 * buffer, or Z_DATA_ERROR if the input data was corrupted.
75 z_uncompress(Byte
*dest
, uLong
*destLen
, const Byte
*source
, uLong sourceLen
)
80 stream
.next_in
= (Byte
*)source
;
81 stream
.avail_in
= (uInt
)sourceLen
;
82 /* Check for source > 64K on 16-bit machine: */
83 if ((uLong
)stream
.avail_in
!= sourceLen
)
86 stream
.next_out
= dest
;
87 stream
.avail_out
= (uInt
)*destLen
;
89 if ((uLong
)stream
.avail_out
!= *destLen
)
92 err
= zlib_inflateInit(&stream
);
96 err
= zlib_inflate(&stream
, Z_FINISH
);
97 if (err
!= Z_STREAM_END
) {
98 zlib_inflateEnd(&stream
);
100 if (err
== Z_NEED_DICT
||
101 (err
== Z_BUF_ERROR
&& stream
.avail_in
== 0))
106 *destLen
= stream
.total_out
;
108 err
= zlib_inflateEnd(&stream
);
110 } /* z_uncompress() */
112 #endif /* SPL_ZMOD_H */