]>
git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/zlib/compress.c
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 /* compress.c -- compress a memory buffer
20 * Copyright (C) 1995-1998 Jean-loup Gailly.
21 * For conditions of distribution and use, see copyright notice in zlib.h
24 /* @(#) $Id: compress.c,v 1.1.1.1 2001/05/18 23:14:03 mb Exp $ */
28 /* ===========================================================================
29 Compresses the source buffer into the destination buffer. The level
30 parameter has the same meaning as in deflateInit. sourceLen is the byte
31 length of the source buffer. Upon entry, destLen is the total size of the
32 destination buffer, which must be at least 0.1% larger than sourceLen plus
33 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
35 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
36 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
37 Z_STREAM_ERROR if the level parameter is invalid.
39 int ZEXPORT
compress2 (dest
, destLen
, source
, sourceLen
, level
)
49 stream
.next_in
= (Bytef
*)source
;
50 stream
.avail_in
= (uInt
)sourceLen
;
52 /* Check for source > 64K on 16-bit machine: */
53 if ((uLong
)stream
.avail_in
!= sourceLen
) return Z_BUF_ERROR
;
55 stream
.next_out
= dest
;
56 stream
.avail_out
= (uInt
)*destLen
;
57 if ((uLong
)stream
.avail_out
!= *destLen
) return Z_BUF_ERROR
;
59 stream
.zalloc
= (alloc_func
)0;
60 stream
.zfree
= (free_func
)0;
61 stream
.opaque
= (voidpf
)0;
63 err
= deflateInit(&stream
, level
);
64 if (err
!= Z_OK
) return err
;
66 err
= deflate(&stream
, Z_FINISH
);
67 if (err
!= Z_STREAM_END
) {
69 return err
== Z_OK
? Z_BUF_ERROR
: err
;
71 *destLen
= stream
.total_out
;
73 err
= deflateEnd(&stream
);
77 /* ===========================================================================
79 int ZEXPORT
compress (dest
, destLen
, source
, sourceLen
)
85 return compress2(dest
, destLen
, source
, sourceLen
, Z_DEFAULT_COMPRESSION
);