aboutsummaryrefslogtreecommitdiff
path: root/gzread.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzread.c')
-rw-r--r--gzread.c84
1 files changed, 16 insertions, 68 deletions
diff --git a/gzread.c b/gzread.c
index dd77381..6034a28 100644
--- a/gzread.c
+++ b/gzread.c
@@ -5,25 +5,12 @@
5 5
6#include "gzguts.h" 6#include "gzguts.h"
7 7
8/* Local functions */
9local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
10local int gz_avail OF((gz_statep));
11local int gz_look OF((gz_statep));
12local int gz_decomp OF((gz_statep));
13local int gz_fetch OF((gz_statep));
14local int gz_skip OF((gz_statep, z_off64_t));
15local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
16
17/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from 8/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
18 state->fd, and update state->eof, state->err, and state->msg as appropriate. 9 state->fd, and update state->eof, state->err, and state->msg as appropriate.
19 This function needs to loop on read(), since read() is not guaranteed to 10 This function needs to loop on read(), since read() is not guaranteed to
20 read the number of bytes requested, depending on the type of descriptor. */ 11 read the number of bytes requested, depending on the type of descriptor. */
21local int gz_load(state, buf, len, have) 12local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
22 gz_statep state; 13 unsigned *have) {
23 unsigned char *buf;
24 unsigned len;
25 unsigned *have;
26{
27 int ret; 14 int ret;
28 unsigned get, max = ((unsigned)-1 >> 2) + 1; 15 unsigned get, max = ((unsigned)-1 >> 2) + 1;
29 16
@@ -53,9 +40,7 @@ local int gz_load(state, buf, len, have)
53 If strm->avail_in != 0, then the current data is moved to the beginning of 40 If strm->avail_in != 0, then the current data is moved to the beginning of
54 the input buffer, and then the remainder of the buffer is loaded with the 41 the input buffer, and then the remainder of the buffer is loaded with the
55 available data from the input file. */ 42 available data from the input file. */
56local int gz_avail(state) 43local int gz_avail(gz_statep state) {
57 gz_statep state;
58{
59 unsigned got; 44 unsigned got;
60 z_streamp strm = &(state->strm); 45 z_streamp strm = &(state->strm);
61 46
@@ -88,9 +73,7 @@ local int gz_avail(state)
88 case, all further file reads will be directly to either the output buffer or 73 case, all further file reads will be directly to either the output buffer or
89 a user buffer. If decompressing, the inflate state will be initialized. 74 a user buffer. If decompressing, the inflate state will be initialized.
90 gz_look() will return 0 on success or -1 on failure. */ 75 gz_look() will return 0 on success or -1 on failure. */
91local int gz_look(state) 76local int gz_look(gz_statep state) {
92 gz_statep state;
93{
94 z_streamp strm = &(state->strm); 77 z_streamp strm = &(state->strm);
95 78
96 /* allocate read buffers and inflate memory */ 79 /* allocate read buffers and inflate memory */
@@ -170,9 +153,7 @@ local int gz_look(state)
170 data. If the gzip stream completes, state->how is reset to LOOK to look for 153 data. If the gzip stream completes, state->how is reset to LOOK to look for
171 the next gzip stream or raw data, once state->x.have is depleted. Returns 0 154 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
172 on success, -1 on failure. */ 155 on success, -1 on failure. */
173local int gz_decomp(state) 156local int gz_decomp(gz_statep state) {
174 gz_statep state;
175{
176 int ret = Z_OK; 157 int ret = Z_OK;
177 unsigned had; 158 unsigned had;
178 z_streamp strm = &(state->strm); 159 z_streamp strm = &(state->strm);
@@ -224,9 +205,7 @@ local int gz_decomp(state)
224 looked for to determine whether to copy or decompress. Returns -1 on error, 205 looked for to determine whether to copy or decompress. Returns -1 on error,
225 otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the 206 otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
226 end of the input file has been reached and all data has been processed. */ 207 end of the input file has been reached and all data has been processed. */
227local int gz_fetch(state) 208local int gz_fetch(gz_statep state) {
228 gz_statep state;
229{
230 z_streamp strm = &(state->strm); 209 z_streamp strm = &(state->strm);
231 210
232 do { 211 do {
@@ -254,10 +233,7 @@ local int gz_fetch(state)
254} 233}
255 234
256/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ 235/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
257local int gz_skip(state, len) 236local int gz_skip(gz_statep state, z_off64_t len) {
258 gz_statep state;
259 z_off64_t len;
260{
261 unsigned n; 237 unsigned n;
262 238
263 /* skip over len bytes or reach end-of-file, whichever comes first */ 239 /* skip over len bytes or reach end-of-file, whichever comes first */
@@ -289,11 +265,7 @@ local int gz_skip(state, len)
289 input. Return the number of bytes read. If zero is returned, either the 265 input. Return the number of bytes read. If zero is returned, either the
290 end of file was reached, or there was an error. state->err must be 266 end of file was reached, or there was an error. state->err must be
291 consulted in that case to determine which. */ 267 consulted in that case to determine which. */
292local z_size_t gz_read(state, buf, len) 268local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
293 gz_statep state;
294 voidp buf;
295 z_size_t len;
296{
297 z_size_t got; 269 z_size_t got;
298 unsigned n; 270 unsigned n;
299 271
@@ -370,11 +342,7 @@ local z_size_t gz_read(state, buf, len)
370} 342}
371 343
372/* -- see zlib.h -- */ 344/* -- see zlib.h -- */
373int ZEXPORT gzread(file, buf, len) 345int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
374 gzFile file;
375 voidp buf;
376 unsigned len;
377{
378 gz_statep state; 346 gz_statep state;
379 347
380 /* get internal structure */ 348 /* get internal structure */
@@ -406,12 +374,7 @@ int ZEXPORT gzread(file, buf, len)
406} 374}
407 375
408/* -- see zlib.h -- */ 376/* -- see zlib.h -- */
409z_size_t ZEXPORT gzfread(buf, size, nitems, file) 377z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) {
410 voidp buf;
411 z_size_t size;
412 z_size_t nitems;
413 gzFile file;
414{
415 z_size_t len; 378 z_size_t len;
416 gz_statep state; 379 gz_statep state;
417 380
@@ -442,9 +405,7 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
442#else 405#else
443# undef gzgetc 406# undef gzgetc
444#endif 407#endif
445int ZEXPORT gzgetc(file) 408int ZEXPORT gzgetc(gzFile file) {
446 gzFile file;
447{
448 unsigned char buf[1]; 409 unsigned char buf[1];
449 gz_statep state; 410 gz_statep state;
450 411
@@ -469,17 +430,12 @@ int ZEXPORT gzgetc(file)
469 return gz_read(state, buf, 1) < 1 ? -1 : buf[0]; 430 return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
470} 431}
471 432
472int ZEXPORT gzgetc_(file) 433int ZEXPORT gzgetc_(gzFile file) {
473gzFile file;
474{
475 return gzgetc(file); 434 return gzgetc(file);
476} 435}
477 436
478/* -- see zlib.h -- */ 437/* -- see zlib.h -- */
479int ZEXPORT gzungetc(c, file) 438int ZEXPORT gzungetc(int c, gzFile file) {
480 int c;
481 gzFile file;
482{
483 gz_statep state; 439 gz_statep state;
484 440
485 /* get internal structure */ 441 /* get internal structure */
@@ -536,11 +492,7 @@ int ZEXPORT gzungetc(c, file)
536} 492}
537 493
538/* -- see zlib.h -- */ 494/* -- see zlib.h -- */
539char * ZEXPORT gzgets(file, buf, len) 495char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
540 gzFile file;
541 char *buf;
542 int len;
543{
544 unsigned left, n; 496 unsigned left, n;
545 char *str; 497 char *str;
546 unsigned char *eol; 498 unsigned char *eol;
@@ -600,9 +552,7 @@ char * ZEXPORT gzgets(file, buf, len)
600} 552}
601 553
602/* -- see zlib.h -- */ 554/* -- see zlib.h -- */
603int ZEXPORT gzdirect(file) 555int ZEXPORT gzdirect(gzFile file) {
604 gzFile file;
605{
606 gz_statep state; 556 gz_statep state;
607 557
608 /* get internal structure */ 558 /* get internal structure */
@@ -620,9 +570,7 @@ int ZEXPORT gzdirect(file)
620} 570}
621 571
622/* -- see zlib.h -- */ 572/* -- see zlib.h -- */
623int ZEXPORT gzclose_r(file) 573int ZEXPORT gzclose_r(gzFile file) {
624 gzFile file;
625{
626 int ret, err; 574 int ret, err;
627 gz_statep state; 575 gz_statep state;
628 576