OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [services/] [compress/] [zlib/] [v2_0/] [src/] [uncompr.c] - Blame information for rev 1254

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.