source: rtems/cpukit/zlib/compress.c

Last change on this file was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on May 3, 2012 at 3:09:24 PM

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/* compress.c -- compress a memory buffer
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#define ZLIB_INTERNAL
7#include "zlib.h"
8
9/* ===========================================================================
10     Compresses the source buffer into the destination buffer. The level
11   parameter has the same meaning as in deflateInit.  sourceLen is the byte
12   length of the source buffer. Upon entry, destLen is the total size of the
13   destination buffer, which must be at least 0.1% larger than sourceLen plus
14   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
15
16     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
17   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
18   Z_STREAM_ERROR if the level parameter is invalid.
19*/
20int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
21    Bytef *dest;
22    uLongf *destLen;
23    const Bytef *source;
24    uLong sourceLen;
25    int level;
26{
27    z_stream stream;
28    int err;
29
30    stream.next_in = (Bytef*)source;
31    stream.avail_in = (uInt)sourceLen;
32#ifdef MAXSEG_64K
33    /* Check for source > 64K on 16-bit machine: */
34    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
35#endif
36    stream.next_out = dest;
37    stream.avail_out = (uInt)*destLen;
38    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
39
40    stream.zalloc = (alloc_func)0;
41    stream.zfree = (free_func)0;
42    stream.opaque = (voidpf)0;
43
44    err = deflateInit(&stream, level);
45    if (err != Z_OK) return err;
46
47    err = deflate(&stream, Z_FINISH);
48    if (err != Z_STREAM_END) {
49        deflateEnd(&stream);
50        return err == Z_OK ? Z_BUF_ERROR : err;
51    }
52    *destLen = stream.total_out;
53
54    err = deflateEnd(&stream);
55    return err;
56}
57
58/* ===========================================================================
59 */
60int ZEXPORT compress (dest, destLen, source, sourceLen)
61    Bytef *dest;
62    uLongf *destLen;
63    const Bytef *source;
64    uLong sourceLen;
65{
66    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
67}
68
69/* ===========================================================================
70     If the default memLevel or windowBits for deflateInit() is changed, then
71   this function needs to be updated.
72 */
73uLong ZEXPORT compressBound (sourceLen)
74    uLong sourceLen;
75{
76    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
77           (sourceLen >> 25) + 13;
78}
Note: See TracBrowser for help on using the repository browser.