/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2009 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526/*27* Zero-length encoding. This is a fast and simple algorithm to eliminate28* runs of zeroes. Each chunk of compressed data begins with a length byte, b.29* If b < n (where n is the compression parameter) then the next b + 1 bytes30* are literal values. If b >= n then the next (256 - b + 1) bytes are zero.31*/3233static int34zle_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)35{36unsigned char *src = s_start;37unsigned char *dst = d_start;38unsigned char *s_end = src + s_len;39unsigned char *d_end = dst + d_len;4041while (src < s_end && dst < d_end) {42int len = 1 + *src++;43if (len <= n) {44while (len-- != 0)45*dst++ = *src++;46} else {47len -= n;48while (len-- != 0)49*dst++ = 0;50}51}52return (dst == d_end ? 0 : -1);53}545556