gzread.c (7648bc9fee8dec6cb3c4941e0165a930fbe8dcb0) gzread.c (cd8822075a38d0734e74b1735e4b5dbef9789170)
1/* gzread.c -- zlib functions for reading gzip files
1/* gzread.c -- zlib functions for reading gzip files
2 * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
2 * Copyright (C) 2004-2017 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* $FreeBSD$ */
7
8#include "gzguts.h"
9#include <unistd.h>
10

--- 301 unchanged lines hidden (view full) ---

312 if (gz_skip(state, state->skip) == -1)
313 return 0;
314 }
315
316 /* get len bytes to buf, or less than len if at the end */
317 got = 0;
318 do {
319 /* set n to the maximum amount of len that fits in an unsigned int */
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* $FreeBSD$ */
7
8#include "gzguts.h"
9#include <unistd.h>
10

--- 301 unchanged lines hidden (view full) ---

312 if (gz_skip(state, state->skip) == -1)
313 return 0;
314 }
315
316 /* get len bytes to buf, or less than len if at the end */
317 got = 0;
318 do {
319 /* set n to the maximum amount of len that fits in an unsigned int */
320 n = -1;
320 n = (unsigned)-1;
321 if (n > len)
321 if (n > len)
322 n = len;
322 n = (unsigned)len;
323
324 /* first just try copying data from the output buffer */
325 if (state->x.have) {
326 if (state->x.have < n)
327 n = state->x.have;
328 memcpy(buf, state->x.next, n);
329 state->x.next += n;
330 state->x.have -= n;

--- 64 unchanged lines hidden (view full) ---

395 /* since an int is returned, make sure len fits in one, otherwise return
396 with an error (this avoids a flaw in the interface) */
397 if ((int)len < 0) {
398 gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
399 return -1;
400 }
401
402 /* read len or fewer bytes to buf */
323
324 /* first just try copying data from the output buffer */
325 if (state->x.have) {
326 if (state->x.have < n)
327 n = state->x.have;
328 memcpy(buf, state->x.next, n);
329 state->x.next += n;
330 state->x.have -= n;

--- 64 unchanged lines hidden (view full) ---

395 /* since an int is returned, make sure len fits in one, otherwise return
396 with an error (this avoids a flaw in the interface) */
397 if ((int)len < 0) {
398 gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
399 return -1;
400 }
401
402 /* read len or fewer bytes to buf */
403 len = gz_read(state, buf, len);
403 len = (unsigned)gz_read(state, buf, len);
404
405 /* check for an error */
406 if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
407 return -1;
408
409 /* return the number of bytes read (this is assured to fit in an int) */
410 return (int)len;
411}

--- 33 unchanged lines hidden (view full) ---

445#ifdef Z_PREFIX_SET
446# undef z_gzgetc
447#else
448# undef gzgetc
449#endif
450int ZEXPORT gzgetc(file)
451 gzFile file;
452{
404
405 /* check for an error */
406 if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
407 return -1;
408
409 /* return the number of bytes read (this is assured to fit in an int) */
410 return (int)len;
411}

--- 33 unchanged lines hidden (view full) ---

445#ifdef Z_PREFIX_SET
446# undef z_gzgetc
447#else
448# undef gzgetc
449#endif
450int ZEXPORT gzgetc(file)
451 gzFile file;
452{
453 int ret;
454 unsigned char buf[1];
455 gz_statep state;
456
457 /* get internal structure */
458 if (file == NULL)
459 return -1;
460 state = (gz_statep)file;
461

--- 5 unchanged lines hidden (view full) ---

467 /* try output buffer (no need to check for skip request) */
468 if (state->x.have) {
469 state->x.have--;
470 state->x.pos++;
471 return *(state->x.next)++;
472 }
473
474 /* nothing there -- try gz_read() */
453 unsigned char buf[1];
454 gz_statep state;
455
456 /* get internal structure */
457 if (file == NULL)
458 return -1;
459 state = (gz_statep)file;
460

--- 5 unchanged lines hidden (view full) ---

466 /* try output buffer (no need to check for skip request) */
467 if (state->x.have) {
468 state->x.have--;
469 state->x.pos++;
470 return *(state->x.next)++;
471 }
472
473 /* nothing there -- try gz_read() */
475 ret = gz_read(state, buf, 1);
476 return ret < 1 ? -1 : buf[0];
474 return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
477}
478
479int ZEXPORT gzgetc_(file)
480gzFile file;
481{
482 return gzgetc(file);
483}
484

--- 173 unchanged lines hidden ---
475}
476
477int ZEXPORT gzgetc_(file)
478gzFile file;
479{
480 return gzgetc(file);
481}
482

--- 173 unchanged lines hidden ---