1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd 22168404Spjd/* 23168404Spjd * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24168404Spjd * Use is subject to license terms. 25168404Spjd */ 26168404Spjd 27168404Spjd#pragma ident "%Z%%M% %I% %E% SMI" 28168404Spjd 29168404Spjd#include <sys/debug.h> 30168404Spjd#include <sys/types.h> 31168404Spjd#include <sys/zmod.h> 32168404Spjd 33168404Spjd#ifdef _KERNEL 34168404Spjd#include <sys/systm.h> 35168404Spjd#else 36168404Spjd#include <strings.h> 37168404Spjd#endif 38168404Spjd 39168404Spjdsize_t 40168404Spjdgzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) 41168404Spjd{ 42168404Spjd size_t dstlen = d_len; 43168404Spjd 44168404Spjd ASSERT(d_len <= s_len); 45168404Spjd 46168404Spjd if (z_compress_level(d_start, &dstlen, s_start, s_len, n) != Z_OK) { 47168404Spjd if (d_len != s_len) 48168404Spjd return (s_len); 49168404Spjd 50168404Spjd bcopy(s_start, d_start, s_len); 51168404Spjd return (s_len); 52168404Spjd } 53168404Spjd 54168404Spjd return (dstlen); 55168404Spjd} 56168404Spjd 57168404Spjd/*ARGSUSED*/ 58168404Spjdint 59168404Spjdgzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) 60168404Spjd{ 61168404Spjd size_t dstlen = d_len; 62168404Spjd 63168404Spjd ASSERT(d_len >= s_len); 64168404Spjd 65168404Spjd if (z_uncompress(d_start, &dstlen, s_start, s_len) != Z_OK) 66168404Spjd return (-1); 67168404Spjd 68168404Spjd return (0); 69168404Spjd} 70