uncompr.c
Go to the documentation of this file.
1 /* uncompr.c -- decompress a memory buffer
2  * Copyright (C) 1995-2003 Jean-loup Gailly.
3  * For conditions of distribution and use, see copyright notice in zlib.h
4  */
5 
6 /* @(#) $Id$ */
7 
8 #define ZLIB_INTERNAL
9 #include "zlib.h"
10 
11 /* ===========================================================================
12  Decompresses the source buffer into the destination buffer. sourceLen is
13  the byte length of the source buffer. Upon entry, destLen is the total
14  size of the destination buffer, which must be large enough to hold the
15  entire uncompressed data. (The size of the uncompressed data must have
16  been saved previously by the compressor and transmitted to the decompressor
17  by some mechanism outside the scope of this compression library.)
18  Upon exit, destLen is the actual size of the compressed buffer.
19  This function can be used to decompress a whole file at once if the
20  input file is mmap'ed.
21 
22  uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
23  enough memory, Z_BUF_ERROR if there was not enough room in the output
24  buffer, or Z_DATA_ERROR if the input data was corrupted.
25 */
26 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
27  Bytef *dest;
28  uLongf *destLen;
29  const Bytef *source;
30  uLong sourceLen;
31 {
32  z_stream stream;
33  int err;
34 
35  stream.next_in = (Bytef*)source;
36  stream.avail_in = (uInt)sourceLen;
37  /* Check for source > 64K on 16-bit machine: */
38  if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
39 
40  stream.next_out = dest;
41  stream.avail_out = (uInt)*destLen;
42  if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
43 
44  stream.zalloc = (alloc_func)0;
45  stream.zfree = (free_func)0;
46 
47  err = inflateInit(&stream);
48  if (err != Z_OK) return err;
49 
50  err = inflate(&stream, Z_FINISH);
51  if (err != Z_STREAM_END) {
52  inflateEnd(&stream);
53  if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
54  return Z_DATA_ERROR;
55  return err;
56  }
57  *destLen = stream.total_out;
58 
59  err = inflateEnd(&stream);
60  return err;
61 }
Bytef
Byte FAR Bytef
Definition: zconf.h:270
z_stream_s::next_in
Bytef * next_in
Definition: zlib.h:83
Z_BUF_ERROR
#define Z_BUF_ERROR
Definition: zlib.h:177
uLong
unsigned long uLong
Definition: zconf.h:264
z_stream_s::zfree
free_func zfree
Definition: zlib.h:95
Z_DATA_ERROR
#define Z_DATA_ERROR
Definition: zlib.h:175
z_stream_s::avail_in
uInt avail_in
Definition: zlib.h:84
Z_FINISH
#define Z_FINISH
Definition: zlib.h:166
Z_NEED_DICT
#define Z_NEED_DICT
Definition: zlib.h:172
uncompress
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.c:26
inflateInit
#define inflateInit(strm)
Definition: zlib.h:1333
z_stream_s::avail_out
uInt avail_out
Definition: zlib.h:88
Z_OK
#define Z_OK
Definition: zlib.h:170
z_stream_s::zalloc
alloc_func zalloc
Definition: zlib.h:94
uLongf
uLong FAR uLongf
Definition: zconf.h:275
Z_STREAM_END
#define Z_STREAM_END
Definition: zlib.h:171
z_stream_s
Definition: zlib.h:82
z_stream_s::next_out
Bytef * next_out
Definition: zlib.h:87
ZEXPORT
#define ZEXPORT
Definition: zconf.h:250
uInt
unsigned int uInt
Definition: zconf.h:263
inflateEnd
int ZEXPORT inflateEnd(z_streamp strm)
Definition: inflate.c:1155
inflate
int ZEXPORT inflate(z_streamp strm, int flush)
Definition: inflate.c:554
z_stream_s::total_out
uLong total_out
Definition: zlib.h:89
zlib.h


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:04