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/infutil.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: infutil.c,v 1.9 2005/02/26 22:58:57 perry Exp $ */
    2 
    3 /* inflate_util.c -- data and routines common to blocks and codes
    4  * Copyright (C) 1995-2002 Mark Adler
    5  * For conditions of distribution and use, see copyright notice in zlib.h
    6  */
    7 
    8 #include "zutil.h"
    9 #include "infblock.h"
   10 #include "inftrees.h"
   11 #include "infcodes.h"
   12 #include "infutil.h"
   13 
   14 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
   15 
   16 /* And'ing with mask[n] masks the lower n bits */
   17 const uInt inflate_mask[17] = {
   18     0x0000,
   19     0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
   20     0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
   21 };
   22 
   23 
   24 #ifndef _ZLIB_NO_ERRMSG
   25 static const char *const zerrlist[] = {
   26         "invalid block type"
   27         "invalid stored block lengths",
   28         "too many length or distance symbols",
   29         "invalid bit length repeat",
   30         "invalid literal/length code",
   31         "invalid distance code",
   32         "oversubscribed dynamic bit lengths tree",
   33         "incomplete dynamic bit lengths tree",
   34         "oversubscribed literal/length tree",
   35         "incomplete literal/length tree",
   36         "oversubscribed distance tree",
   37         "incomplete distance tree",
   38         "empty distance tree with lengths",
   39 };
   40 
   41 char *zerror(e)
   42         int e;
   43 {
   44         return __UNCONST(zerrlist[e]);
   45 }
   46 #endif
   47 
   48 /* copy as much as possible from the sliding window to the output area */
   49 int inflate_flush(s, z, r)
   50 inflate_blocks_statef *s;
   51 z_streamp z;
   52 int r;
   53 {
   54   uInt n;
   55   Bytef *p;
   56   Bytef *q;
   57 
   58   /* local copies of source and destination pointers */
   59   p = z->next_out;
   60   q = s->read;
   61 
   62   /* compute number of bytes to copy as far as end of window */
   63   n = (uInt)((q <= s->write ? s->write : s->end) - q);
   64   if (n > z->avail_out) n = z->avail_out;
   65   if (n && r == Z_BUF_ERROR) r = Z_OK;
   66 
   67   /* update counters */
   68   z->avail_out -= n;
   69   z->total_out += n;
   70 
   71   /* copy as far as end of window */
   72   zmemcpy(p, q, n);
   73   p += n;
   74   q += n;
   75 
   76   /* see if more to copy at beginning of window */
   77   if (q == s->end)
   78   {
   79     /* wrap pointers */
   80     q = s->window;
   81     if (s->write == s->end)
   82       s->write = s->window;
   83 
   84     /* compute bytes to copy */
   85     n = (uInt)(s->write - q);
   86     if (n > z->avail_out) n = z->avail_out;
   87     if (n && r == Z_BUF_ERROR) r = Z_OK;
   88 
   89     /* update counters */
   90     z->avail_out -= n;
   91     z->total_out += n;
   92 
   93     /* copy */
   94     zmemcpy(p, q, n);
   95     p += n;
   96     q += n;
   97   }
   98 
   99   /* update pointers */
  100   z->next_out = p;
  101   s->read = q;
  102 
  103   /* done */
  104   return r;
  105 }

Cache object: 473ce8781c7a6de36b2d1cf9567a614f


[ 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.