Mercurial > hg > CbC > CbC_gcc
annotate zlib/uncompr.c @ 103:edcadcec937d
modify __rectype
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 23 Mar 2012 17:11:33 +0900 |
parents | ae3a4bfb450b |
children | 04ced10e8804 |
rev | line source |
---|---|
51
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /* uncompr.c -- decompress a memory buffer |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 * Copyright (C) 1995-2003 Jean-loup Gailly. |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 * For conditions of distribution and use, see copyright notice in zlib.h |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 */ |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 /* @(#) $Id: uncompr.c,v 1.1.1.2 2002/03/11 21:53:27 tromey Exp $ */ |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 #define ZLIB_INTERNAL |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 #include "zlib.h" |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 /* =========================================================================== |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 Decompresses the source buffer into the destination buffer. sourceLen is |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 the byte length of the source buffer. Upon entry, destLen is the total |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 size of the destination buffer, which must be large enough to hold the |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 entire uncompressed data. (The size of the uncompressed data must have |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 been saved previously by the compressor and transmitted to the decompressor |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 by some mechanism outside the scope of this compression library.) |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 Upon exit, destLen is the actual size of the compressed buffer. |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 This function can be used to decompress a whole file at once if the |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 input file is mmap'ed. |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 enough memory, Z_BUF_ERROR if there was not enough room in the output |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 buffer, or Z_DATA_ERROR if the input data was corrupted. |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 */ |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 int ZEXPORT uncompress (dest, destLen, source, sourceLen) |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 Bytef *dest; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 uLongf *destLen; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 const Bytef *source; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 uLong sourceLen; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 { |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 z_stream stream; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 int err; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 stream.next_in = (Bytef*)source; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 stream.avail_in = (uInt)sourceLen; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 /* Check for source > 64K on 16-bit machine: */ |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 stream.next_out = dest; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 stream.avail_out = (uInt)*destLen; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 stream.zalloc = (alloc_func)0; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 stream.zfree = (free_func)0; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 err = inflateInit(&stream); |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 if (err != Z_OK) return err; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 err = inflate(&stream, Z_FINISH); |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 if (err != Z_STREAM_END) { |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 inflateEnd(&stream); |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 return Z_DATA_ERROR; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 return err; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 } |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 *destLen = stream.total_out; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 err = inflateEnd(&stream); |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 return err; |
ae3a4bfb450b
add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 } |