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>
15 uInt n
; /* number of bytes to look at */
16 Byte
*p
; /* pointer to bytes */
17 uInt m
; /* number of marker bytes found in a row */
18 uLong r
, w
; /* temporaries to save total_in and total_out */
21 if (z
== NULL
|| z
->state
== NULL
)
22 return Z_STREAM_ERROR
;
23 if (z
->state
->mode
!= I_BAD
)
25 z
->state
->mode
= I_BAD
;
26 z
->state
->sub
.marker
= 0;
28 if ((n
= z
->avail_in
) == 0)
31 m
= z
->state
->sub
.marker
;
36 static const Byte mark
[4] = {0, 0, 0xff, 0xff};
47 z
->total_in
+= p
- z
->next_in
;
50 z
->state
->sub
.marker
= m
;
52 /* return no joy or set up to restart on a new block */
55 r
= z
->total_in
; w
= z
->total_out
;
57 z
->total_in
= r
; z
->total_out
= w
;
58 z
->state
->mode
= BLOCKS
;
64 /* Returns true if inflate is currently at the end of a block generated
65 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
66 * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
67 * but removes the length bytes of the resulting empty stored block. When
68 * decompressing, PPP checks that at the end of input packet, inflate is
69 * waiting for these length bytes.
72 int zlib_inflateSyncPoint(
76 if (z
== NULL
|| z
->state
== NULL
|| z
->state
->blocks
== NULL
)
77 return Z_STREAM_ERROR
;
78 return zlib_inflate_blocks_sync_point(z
->state
->blocks
);
83 * This subroutine adds the data at next_in/avail_in to the output history
84 * without performing any output. The output buffer must be "caught up";
85 * i.e. no pending output (hence s->read equals s->write), and the state must
86 * be BLOCKS (i.e. we should be willing to see the start of a series of
87 * BLOCKS). On exit, the output will also be caught up, and the checksum
88 * will have been updated if need be.
90 static int zlib_inflate_addhistory(inflate_blocks_statef
*s
,
93 uLong b
; /* bit buffer */ /* NOT USED HERE */
94 uInt k
; /* bits in bit buffer */ /* NOT USED HERE */
95 uInt t
; /* temporary storage */
96 Byte
*p
; /* input data pointer */
97 uInt n
; /* bytes available there */
98 Byte
*q
; /* output window write pointer */
99 uInt m
; /* bytes to end of window or read pointer */
101 if (s
->read
!= s
->write
)
102 return Z_STREAM_ERROR
;
106 /* we're ready to rock */
108 /* while there is input ready, copy to output buffer, moving
109 * pointers as needed.
112 t
= n
; /* how many to do */
113 /* is there room until end of buffer? */
115 /* update check information */
116 if (s
->checkfn
!= NULL
)
117 s
->check
= (*s
->checkfn
)(s
->check
, q
, t
);
123 s
->read
= q
; /* drag read pointer forward */
124 /* WWRAP */ /* expand WWRAP macro by hand to handle s->read */
126 s
->read
= q
= s
->window
;
136 * This subroutine adds the data at next_in/avail_in to the output history
137 * without performing any output. The output buffer must be "caught up";
138 * i.e. no pending output (hence s->read equals s->write), and the state must
139 * be BLOCKS (i.e. we should be willing to see the start of a series of
140 * BLOCKS). On exit, the output will also be caught up, and the checksum
141 * will have been updated if need be.
144 int zlib_inflateIncomp(
149 if (z
->state
->mode
!= BLOCKS
)
151 return zlib_inflate_addhistory(z
->state
->blocks
, z
);