ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
uncompr.c
Go to the documentation of this file.
1/* uncompr.c -- decompress a memory buffer
2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
12
13#define ZLIB_INTERNAL
14#include "zlib.h"
15
17
18/* ===========================================================================
19 Decompresses the source buffer into the destination buffer. sourceLen is
20 the byte length of the source buffer. Upon entry, destLen is the total
21 size of the destination buffer, which must be large enough to hold the
22 entire uncompressed data. (The size of the uncompressed data must have
23 been saved previously by the compressor and transmitted to the decompressor
24 by some mechanism outside the scope of this compression library.)
25 Upon exit, destLen is the actual size of the compressed buffer.
26
27 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
28 enough memory, Z_BUF_ERROR if there was not enough room in the output
29 buffer, or Z_DATA_ERROR if the input data was corrupted.
30*/
31int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
32{
33 z_stream stream;
34 int err;
35
36 stream.next_in = (Bytef*)source;
37 stream.avail_in = (uInt)sourceLen;
38 /* Check for source > 64K on 16-bit machine: */
39 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
40
41 stream.next_out = dest;
42 stream.avail_out = (uInt)*destLen;
43 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
44
45 stream.zalloc = (alloc_func)0;
46 stream.zfree = (free_func)0;
47
48 err = inflateInit(&stream);
49 if (err != Z_OK) return err;
50
51 err = inflate(&stream, Z_FINISH);
52 if (err != Z_STREAM_END) {
53 inflateEnd(&stream);
54 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
55 return Z_DATA_ERROR;
56 return err;
57 }
58 *destLen = stream.total_out;
59
60 err = inflateEnd(&stream);
61 return err;
62}
63
64
65
67
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int ZEXPORT inflate(z_streamp strm, int flush)
Definition inflate.c:580
int ZEXPORT inflateEnd(z_streamp strm)
Definition inflate.c:1227
uInt avail_in
Definition zlib.h:95
Bytef * next_in
Definition zlib.h:94
alloc_func zalloc
Definition zlib.h:105
uInt avail_out
Definition zlib.h:99
free_func zfree
Definition zlib.h:106
uLong total_out
Definition zlib.h:100
Bytef * next_out
Definition zlib.h:98
ABC_NAMESPACE_IMPL_START int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition uncompr.c:31
uLong FAR uLongf
Definition zconf.h:347
#define ZEXPORT
Definition zconf.h:322
unsigned int uInt
Definition zconf.h:335
unsigned long uLong
Definition zconf.h:336
Byte FAR Bytef
Definition zconf.h:342
#define Z_NEED_DICT
Definition zlib.h:183
#define Z_BUF_ERROR
Definition zlib.h:188
#define Z_STREAM_END
Definition zlib.h:182
#define Z_FINISH
Definition zlib.h:176
#define Z_OK
Definition zlib.h:181
#define Z_DATA_ERROR
Definition zlib.h:186
struct z_stream_s z_stream
#define inflateInit(strm)
Definition zlib.h:1556