1*c9431fa1Sahl /*
2*c9431fa1Sahl * CDDL HEADER START
3*c9431fa1Sahl *
4*c9431fa1Sahl * The contents of this file are subject to the terms of the
5*c9431fa1Sahl * Common Development and Distribution License (the "License").
6*c9431fa1Sahl * You may not use this file except in compliance with the License.
7*c9431fa1Sahl *
8*c9431fa1Sahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*c9431fa1Sahl * or http://www.opensolaris.org/os/licensing.
10*c9431fa1Sahl * See the License for the specific language governing permissions
11*c9431fa1Sahl * and limitations under the License.
12*c9431fa1Sahl *
13*c9431fa1Sahl * When distributing Covered Code, include this CDDL HEADER in each
14*c9431fa1Sahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*c9431fa1Sahl * If applicable, add the following below this CDDL HEADER, with the
16*c9431fa1Sahl * fields enclosed by brackets "[]" replaced with your own identifying
17*c9431fa1Sahl * information: Portions Copyright [yyyy] [name of copyright owner]
18*c9431fa1Sahl *
19*c9431fa1Sahl * CDDL HEADER END
20*c9431fa1Sahl */
21*c9431fa1Sahl
22*c9431fa1Sahl /*
23*c9431fa1Sahl * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24*c9431fa1Sahl * Use is subject to license terms.
25*c9431fa1Sahl */
26*c9431fa1Sahl
27*c9431fa1Sahl #pragma ident "%Z%%M% %I% %E% SMI"
28*c9431fa1Sahl
29*c9431fa1Sahl #include <sys/debug.h>
30*c9431fa1Sahl #include <sys/types.h>
31*c9431fa1Sahl #include <sys/zmod.h>
32*c9431fa1Sahl
33*c9431fa1Sahl #ifdef _KERNEL
34*c9431fa1Sahl #include <sys/systm.h>
35*c9431fa1Sahl #else
36*c9431fa1Sahl #include <strings.h>
37*c9431fa1Sahl #endif
38*c9431fa1Sahl
39*c9431fa1Sahl size_t
gzip_compress(void * s_start,void * d_start,size_t s_len,size_t d_len,int n)40*c9431fa1Sahl gzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
41*c9431fa1Sahl {
42*c9431fa1Sahl size_t dstlen = d_len;
43*c9431fa1Sahl
44*c9431fa1Sahl ASSERT(d_len <= s_len);
45*c9431fa1Sahl
46*c9431fa1Sahl if (z_compress_level(d_start, &dstlen, s_start, s_len, n) != Z_OK) {
47*c9431fa1Sahl if (d_len != s_len)
48*c9431fa1Sahl return (s_len);
49*c9431fa1Sahl
50*c9431fa1Sahl bcopy(s_start, d_start, s_len);
51*c9431fa1Sahl return (s_len);
52*c9431fa1Sahl }
53*c9431fa1Sahl
54*c9431fa1Sahl return (dstlen);
55*c9431fa1Sahl }
56*c9431fa1Sahl
57*c9431fa1Sahl /*ARGSUSED*/
58*c9431fa1Sahl int
gzip_decompress(void * s_start,void * d_start,size_t s_len,size_t d_len,int n)59*c9431fa1Sahl gzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
60*c9431fa1Sahl {
61*c9431fa1Sahl size_t dstlen = d_len;
62*c9431fa1Sahl
63*c9431fa1Sahl ASSERT(d_len >= s_len);
64*c9431fa1Sahl
65*c9431fa1Sahl if (z_uncompress(d_start, &dstlen, s_start, s_len) != Z_OK)
66*c9431fa1Sahl return (-1);
67*c9431fa1Sahl
68*c9431fa1Sahl return (0);
69*c9431fa1Sahl }
70