The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/lib/libz/uncompr.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: uncompr.c,v 1.2 2002/03/12 00:42:24 fvdl Exp $ */
    2 
    3 /* uncompr.c -- decompress a memory buffer
    4  * Copyright (C) 1995-2002 Jean-loup Gailly.
    5  * For conditions of distribution and use, see copyright notice in zlib.h 
    6  */
    7 
    8 /* @(#) $Id: uncompr.c,v 1.2 2002/03/12 00:42:24 fvdl Exp $ */
    9 
   10 #include "zlib.h"
   11 
   12 /* ===========================================================================
   13      Decompresses the source buffer into the destination buffer.  sourceLen is
   14    the byte length of the source buffer. Upon entry, destLen is the total
   15    size of the destination buffer, which must be large enough to hold the
   16    entire uncompressed data. (The size of the uncompressed data must have
   17    been saved previously by the compressor and transmitted to the decompressor
   18    by some mechanism outside the scope of this compression library.)
   19    Upon exit, destLen is the actual size of the compressed buffer.
   20      This function can be used to decompress a whole file at once if the
   21    input file is mmap'ed.
   22 
   23      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
   24    enough memory, Z_BUF_ERROR if there was not enough room in the output
   25    buffer, or Z_DATA_ERROR if the input data was corrupted.
   26 */
   27 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
   28     Bytef *dest;
   29     uLongf *destLen;
   30     const Bytef *source;
   31     uLong sourceLen;
   32 {
   33     z_stream stream;
   34     int err;
   35 
   36     stream.next_in = (Bytef*)source;
   37     stream.avail_in = (uInt)sourceLen;
   38     /* Check for source > 64K on 16-bit machine: */
   39     if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
   40 
   41     stream.next_out = dest;
   42     stream.avail_out = (uInt)*destLen;
   43     if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
   44 
   45     stream.zalloc = (alloc_func)0;
   46     stream.zfree = (free_func)0;
   47 
   48     err = inflateInit(&stream);
   49     if (err != Z_OK) return err;
   50 
   51     err = inflate(&stream, Z_FINISH);
   52     if (err != Z_STREAM_END) {
   53         inflateEnd(&stream);
   54         return err == Z_OK ? Z_BUF_ERROR : err;
   55     }
   56     *destLen = stream.total_out;
   57 
   58     err = inflateEnd(&stream);
   59     return err;
   60 }

Cache object: bbeaf2aa4c993477d05be0dfd80fa99a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.