1 /* inflate.c -- zlib interface to inflate modules
2 * Copyright (C) 1995-1998 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
6 #include <linux/zutil.h>
14 uInt n; /* number of bytes to look at */
15 Byte *p; /* pointer to bytes */
16 uInt m; /* number of marker bytes found in a row */
17 uLong r, w; /* temporaries to save total_in and total_out */
20 if (z == NULL || z->state == NULL)
21 return Z_STREAM_ERROR;
22 if (z->state->mode != I_BAD)
24 z->state->mode = I_BAD;
25 z->state->sub.marker = 0;
27 if ((n = z->avail_in) == 0)
30 m = z->state->sub.marker;
35 static const Byte mark[4] = {0, 0, 0xff, 0xff};
46 z->total_in += p - z->next_in;
49 z->state->sub.marker = m;
51 /* return no joy or set up to restart on a new block */
54 r = z->total_in; w = z->total_out;
56 z->total_in = r; z->total_out = w;
57 z->state->mode = BLOCKS;
62 /* Returns true if inflate is currently at the end of a block generated
63 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
64 * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
65 * but removes the length bytes of the resulting empty stored block. When
66 * decompressing, PPP checks that at the end of input packet, inflate is
67 * waiting for these length bytes.
69 int zlib_inflateSyncPoint(
73 if (z == NULL || z->state == NULL || z->state->blocks == NULL)
74 return Z_STREAM_ERROR;
75 return zlib_inflate_blocks_sync_point(z->state->blocks);
79 * This subroutine adds the data at next_in/avail_in to the output history
80 * without performing any output. The output buffer must be "caught up";
81 * i.e. no pending output (hence s->read equals s->write), and the state must
82 * be BLOCKS (i.e. we should be willing to see the start of a series of
83 * BLOCKS). On exit, the output will also be caught up, and the checksum
84 * will have been updated if need be.
86 static int zlib_inflate_addhistory(inflate_blocks_statef *s,
89 uLong b; /* bit buffer */ /* NOT USED HERE */
90 uInt k; /* bits in bit buffer */ /* NOT USED HERE */
91 uInt t; /* temporary storage */
92 Byte *p; /* input data pointer */
93 uInt n; /* bytes available there */
94 Byte *q; /* output window write pointer */
95 uInt m; /* bytes to end of window or read pointer */
97 if (s->read != s->write)
98 return Z_STREAM_ERROR;
102 /* we're ready to rock */
104 /* while there is input ready, copy to output buffer, moving
105 * pointers as needed.
108 t = n; /* how many to do */
109 /* is there room until end of buffer? */
111 /* update check information */
112 if (s->checkfn != NULL)
113 s->check = (*s->checkfn)(s->check, q, t);
119 s->read = q; /* drag read pointer forward */
120 /* WWRAP */ /* expand WWRAP macro by hand to handle s->read */
122 s->read = q = s->window;
132 * This subroutine adds the data at next_in/avail_in to the output history
133 * without performing any output. The output buffer must be "caught up";
134 * i.e. no pending output (hence s->read equals s->write), and the state must
135 * be BLOCKS (i.e. we should be willing to see the start of a series of
136 * BLOCKS). On exit, the output will also be caught up, and the checksum
137 * will have been updated if need be.
140 int zlib_inflateIncomp(
145 if (z->state->mode != BLOCKS)
147 return zlib_inflate_addhistory(z->state->blocks, z);