]> git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/zlib/uncompr.c
Security-30.1.tar.gz
[apple/security.git] / SecurityServer / MacYarrow / zlib / uncompr.c
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /* uncompr.c -- decompress a memory buffer
20 * Copyright (C) 1995-1998 Jean-loup Gailly.
21 * For conditions of distribution and use, see copyright notice in zlib.h
22 */
23
24 /* @(#) $Id: uncompr.c,v 1.1.1.1 2001/05/18 23:14:03 mb Exp $ */
25
26 #include "zlib.h"
27
28 /* ===========================================================================
29 Decompresses the source buffer into the destination buffer. sourceLen is
30 the byte length of the source buffer. Upon entry, destLen is the total
31 size of the destination buffer, which must be large enough to hold the
32 entire uncompressed data. (The size of the uncompressed data must have
33 been saved previously by the compressor and transmitted to the decompressor
34 by some mechanism outside the scope of this compression library.)
35 Upon exit, destLen is the actual size of the compressed buffer.
36 This function can be used to decompress a whole file at once if the
37 input file is mmap'ed.
38
39 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
40 enough memory, Z_BUF_ERROR if there was not enough room in the output
41 buffer, or Z_DATA_ERROR if the input data was corrupted.
42 */
43 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
44 Bytef *dest;
45 uLongf *destLen;
46 const Bytef *source;
47 uLong sourceLen;
48 {
49 z_stream stream;
50 int err;
51
52 stream.next_in = (Bytef*)source;
53 stream.avail_in = (uInt)sourceLen;
54 /* Check for source > 64K on 16-bit machine: */
55 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
56
57 stream.next_out = dest;
58 stream.avail_out = (uInt)*destLen;
59 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
60
61 stream.zalloc = (alloc_func)0;
62 stream.zfree = (free_func)0;
63
64 err = inflateInit(&stream);
65 if (err != Z_OK) return err;
66
67 err = inflate(&stream, Z_FINISH);
68 if (err != Z_STREAM_END) {
69 inflateEnd(&stream);
70 return err == Z_OK ? Z_BUF_ERROR : err;
71 }
72 *destLen = stream.total_out;
73
74 err = inflateEnd(&stream);
75 return err;
76 }