annotate lib/zlib/uncompr.c @ 49:25fabc49627b

Слияние
author Ritor1
date Tue, 23 Oct 2012 17:34:20 +0600
parents 8b8875f5b359
children
rev   line source
0
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1 /* uncompr.c -- decompress a memory buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2 * Copyright (C) 1995-1998 Jean-loup Gailly.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4 */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6 /* @(#) $Id$ */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
7
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
8 #include "zlib.h"
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
9
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
10 /* ===========================================================================
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
11 Decompresses the source buffer into the destination buffer. sourceLen is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
12 the byte length of the source buffer. Upon entry, destLen is the total
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
13 size of the destination buffer, which must be large enough to hold the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
14 entire uncompressed data. (The size of the uncompressed data must have
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
15 been saved previously by the compressor and transmitted to the decompressor
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
16 by some mechanism outside the scope of this compression library.)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
17 Upon exit, destLen is the actual size of the compressed buffer.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
18 This function can be used to decompress a whole file at once if the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
19 input file is mmap'ed.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
20
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
21 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
22 enough memory, Z_BUF_ERROR if there was not enough room in the output
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
23 buffer, or Z_DATA_ERROR if the input data was corrupted.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
24 */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
25 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
26 Bytef *dest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
27 uLongf *destLen;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
28 const Bytef *source;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
29 uLong sourceLen;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
30 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
31 z_stream stream;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
32 int err;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
33
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
34 stream.next_in = (Bytef*)source;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
35 stream.avail_in = (uInt)sourceLen;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
36 /* Check for source > 64K on 16-bit machine: */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
37 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
38
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
39 stream.next_out = dest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
40 stream.avail_out = (uInt)*destLen;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
41 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
42
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
43 stream.zalloc = (alloc_func)0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
44 stream.zfree = (free_func)0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
45
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
46 err = inflateInit(&stream);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
47 if (err != Z_OK) return err;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
48
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
49 err = inflate(&stream, Z_FINISH);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
50 if (err != Z_STREAM_END) {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
51 inflateEnd(&stream);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
52 return err == Z_OK ? Z_BUF_ERROR : err;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
53 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
54 *destLen = stream.total_out;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
55
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
56 err = inflateEnd(&stream);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
57 return err;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
58 }