annotate lib/zlib/uncompr.c @ 793:290afbd48b6b

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