~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/zlib/compress.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-07-12 23:49:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100712234936-juawrr3etzhr2qpv
Tags: 3.1.2-1
* New maintainer (closes: #532039).
* New upstream version (closes: #461121):
  - includes launcher (closes: #396058).
* Fix the reference to the X Window System in the description (closes:
  #411815).
* Move to main, DFSG-free ROMs are available (see README.Debian).
* Enhance the package description.
* Drop the libslang2-dev dependency (closes: #560274).
* Remove the Encoding entry from stella.desktop.
* Avoid ignoring errors when cleaning.
* Add ${misc:Depends} to the package dependencies.
* Provide a doc-base file to install the documentation using doc-base.
* Switch to debhelper 7 with a simplified rules file.
* Use autotools-dev to provide updated configuration files.
* Update to Standards-Version 3.9.0:
  - Move to menu section Applications/Emulators.
  - Move the homepage declaration.
* Re-write the manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* compress.c -- compress 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: compress.c 1926 2010-01-29 23:37:33Z stephena $ */
 
7
 
 
8
#define ZLIB_INTERNAL
 
9
#include "zlib.h"
 
10
 
 
11
/* ===========================================================================
 
12
     Compresses the source buffer into the destination buffer. The level
 
13
   parameter has the same meaning as in deflateInit.  sourceLen is the byte
 
14
   length of the source buffer. Upon entry, destLen is the total size of the
 
15
   destination buffer, which must be at least 0.1% larger than sourceLen plus
 
16
   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
 
17
 
 
18
     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 
19
   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
 
20
   Z_STREAM_ERROR if the level parameter is invalid.
 
21
*/
 
22
int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
 
23
                       uLong sourceLen, int level)
 
24
{
 
25
    z_stream stream;
 
26
    int err;
 
27
 
 
28
    stream.next_in = (Bytef*)source;
 
29
    stream.avail_in = (uInt)sourceLen;
 
30
#ifdef MAXSEG_64K
 
31
    /* Check for source > 64K on 16-bit machine: */
 
32
    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
 
33
#endif
 
34
    stream.next_out = dest;
 
35
    stream.avail_out = (uInt)*destLen;
 
36
    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
 
37
 
 
38
    stream.zalloc = (alloc_func)0;
 
39
    stream.zfree = (free_func)0;
 
40
    stream.opaque = (voidpf)0;
 
41
 
 
42
    err = deflateInit(&stream, level);
 
43
    if (err != Z_OK) return err;
 
44
 
 
45
    err = deflate(&stream, Z_FINISH);
 
46
    if (err != Z_STREAM_END) {
 
47
        deflateEnd(&stream);
 
48
        return err == Z_OK ? Z_BUF_ERROR : err;
 
49
    }
 
50
    *destLen = stream.total_out;
 
51
 
 
52
    err = deflateEnd(&stream);
 
53
    return err;
 
54
}
 
55
 
 
56
/* ===========================================================================
 
57
 */
 
58
int ZEXPORT compress (Bytef *dest, uLongf *destLen,
 
59
                      const Bytef *source, uLong sourceLen)
 
60
{
 
61
    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
 
62
}
 
63
 
 
64
/* ===========================================================================
 
65
     If the default memLevel or windowBits for deflateInit() is changed, then
 
66
   this function needs to be updated.
 
67
 */
 
68
uLong ZEXPORT compressBound (uLong sourceLen)
 
69
{
 
70
    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
 
71
}