annotate zlib/uncompr.c @ 3:5a977ccbc7a9 default tip

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