• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* inflate_p.h -- Private inline functions and macros shared with more than one deflate method
2  *
3  */
4 
5 #ifndef INFLATE_P_H
6 #define INFLATE_P_H
7 
8 /*
9  *   Macros shared by inflate() and inflateBack()
10  */
11 
12 /* check function to use adler32() for zlib or crc32() for gzip */
13 #ifdef GUNZIP
14 #  define UPDATE(check, buf, len) \
15     (state->flags ? PREFIX(crc32)(check, buf, len) : functable.adler32(check, buf, len))
16 #else
17 #  define UPDATE(check, buf, len) functable.adler32(check, buf, len)
18 #endif
19 
20 /* check macros for header crc */
21 #ifdef GUNZIP
22 #  define CRC2(check, word) \
23     do { \
24         hbuf[0] = (unsigned char)(word); \
25         hbuf[1] = (unsigned char)((word) >> 8); \
26         check = PREFIX(crc32)(check, hbuf, 2); \
27     } while (0)
28 
29 #  define CRC4(check, word) \
30     do { \
31         hbuf[0] = (unsigned char)(word); \
32         hbuf[1] = (unsigned char)((word) >> 8); \
33         hbuf[2] = (unsigned char)((word) >> 16); \
34         hbuf[3] = (unsigned char)((word) >> 24); \
35         check = PREFIX(crc32)(check, hbuf, 4); \
36     } while (0)
37 #endif
38 
39 /* Load registers with state in inflate() for speed */
40 #define LOAD() \
41     do { \
42         put = strm->next_out; \
43         left = strm->avail_out; \
44         next = strm->next_in; \
45         have = strm->avail_in; \
46         hold = state->hold; \
47         bits = state->bits; \
48     } while (0)
49 
50 /* Restore state from registers in inflate() */
51 #define RESTORE() \
52     do { \
53         strm->next_out = put; \
54         strm->avail_out = left; \
55         strm->next_in = (z_const unsigned char *)next; \
56         strm->avail_in = have; \
57         state->hold = hold; \
58         state->bits = bits; \
59     } while (0)
60 
61 /* Clear the input bit accumulator */
62 #define INITBITS() \
63     do { \
64         hold = 0; \
65         bits = 0; \
66     } while (0)
67 
68 /* Ensure that there is at least n bits in the bit accumulator.  If there is
69    not enough available input to do that, then return from inflate()/inflateBack(). */
70 #define NEEDBITS(n) \
71     do { \
72         while (bits < (unsigned)(n)) \
73             PULLBYTE(); \
74     } while (0)
75 
76 /* Return the low n bits of the bit accumulator (n < 16) */
77 #define BITS(n) \
78     (hold & ((1U << (unsigned)(n)) - 1))
79 
80 /* Remove n bits from the bit accumulator */
81 #define DROPBITS(n) \
82     do { \
83         hold >>= (n); \
84         bits -= (unsigned)(n); \
85     } while (0)
86 
87 /* Remove zero to seven bits as needed to go to a byte boundary */
88 #define BYTEBITS() \
89     do { \
90         hold >>= bits & 7; \
91         bits -= bits & 7; \
92     } while (0)
93 
94 #endif
95