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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [compress/] [zlib/] [v2_0/] [src/] [compress.c] - Blame information for rev 584

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

Line No. Rev Author Line
1 27 unneback
/* compress.c -- compress 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: compress.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
     Compresses the source buffer into the destination buffer. The level
16
   parameter has the same meaning as in deflateInit.  sourceLen is the byte
17
   length of the source buffer. Upon entry, destLen is the total size of the
18
   destination buffer, which must be at least 0.1% larger than sourceLen plus
19
   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
20
 
21
     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
22
   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
23
   Z_STREAM_ERROR if the level parameter is invalid.
24
*/
25
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
26
    Bytef *dest;
27
    uLongf *destLen;
28
    const Bytef *source;
29
    uLong sourceLen;
30
    int level;
31
{
32
    z_stream stream;
33
    int err;
34
 
35
    stream.next_in = (Bytef*)source;
36
    stream.avail_in = (uInt)sourceLen;
37
#ifdef MAXSEG_64K
38
    /* Check for source > 64K on 16-bit machine: */
39
    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
40
#endif
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
    stream.opaque = (voidpf)0;
48
 
49
    err = deflateInit(&stream, level);
50
    if (err != Z_OK) return err;
51
 
52
    err = deflate(&stream, Z_FINISH);
53
    if (err != Z_STREAM_END) {
54
        deflateEnd(&stream);
55
        return err == Z_OK ? Z_BUF_ERROR : err;
56
    }
57
    *destLen = stream.total_out;
58
 
59
    err = deflateEnd(&stream);
60
    return err;
61
}
62
 
63
/* ===========================================================================
64
 */
65
int ZEXPORT compress (dest, destLen, source, sourceLen)
66
    Bytef *dest;
67
    uLongf *destLen;
68
    const Bytef *source;
69
    uLong sourceLen;
70
{
71
    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
72
}

powered by: WebSVN 2.1.0

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