9 local int gz_load OF((gz_statep, 
unsigned char *, 
unsigned, 
unsigned *));
 
   20 local int gz_load(gz_statep state, 
unsigned char *buf, 
unsigned len, 
unsigned *have)
 
   26         ret = read(state->fd, buf + *have, len - *have);
 
   30     } 
while (*have < len);
 
   32         gz_error(state, Z_ERRNO, zstrerror());
 
   50     z_streamp strm = &(state->strm);
 
   52     if (state->err != Z_OK && state->err != Z_BUF_ERROR)
 
   54     if (state->eof == 0) {
 
   56             unsigned char *p = state->in, *q = strm->next_in;
 
   57             unsigned n = strm->avail_in;
 
   62         if (
gz_load(state, state->in + strm->avail_in,
 
   63                     state->size - strm->avail_in, &got) == -1)
 
   65         strm->avail_in += got;
 
   66         strm->next_in = state->in;
 
   82     z_streamp strm = &(state->strm);
 
   85     if (state->size == 0) {
 
   87         state->in = (
unsigned char *)malloc(state->want);
 
   88         state->out = (
unsigned char *)malloc(state->want << 1);
 
   89         if (state->in == NULL || state->out == NULL) {
 
   90             if (state->out != NULL)
 
   92             if (state->in != NULL)
 
   94             gz_error(state, Z_MEM_ERROR, 
"out of memory");
 
   97         state->size = state->want;
 
  100         state->strm.zalloc = Z_NULL;
 
  101         state->strm.zfree = Z_NULL;
 
  102         state->strm.opaque = Z_NULL;
 
  103         state->strm.avail_in = 0;
 
  104         state->strm.next_in = Z_NULL;
 
  105         if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) {    
 
  109             gz_error(state, Z_MEM_ERROR, 
"out of memory");
 
  115     if (strm->avail_in < 2) {
 
  118         if (strm->avail_in == 0)
 
  129     if (strm->avail_in > 1 &&
 
  130             strm->next_in[0] == 31 && strm->next_in[1] == 139) {
 
  139     if (state->direct == 0) {
 
  149     state->x.next = state->out;
 
  150     if (strm->avail_in) {
 
  151         memcpy(state->x.next, strm->next_in, strm->avail_in);
 
  152         state->x.have = strm->avail_in;
 
  169     z_streamp strm = &(state->strm);
 
  172     had = strm->avail_out;
 
  175         if (strm->avail_in == 0 && 
gz_avail(state) == -1)
 
  177         if (strm->avail_in == 0) {
 
  178             gz_error(state, Z_BUF_ERROR, 
"unexpected end of file");
 
  183         ret = 
inflate(strm, Z_NO_FLUSH);
 
  184         if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
 
  186                      "internal error: inflate stream corrupt");
 
  189         if (ret == Z_MEM_ERROR) {
 
  190             gz_error(state, Z_MEM_ERROR, 
"out of memory");
 
  193         if (ret == Z_DATA_ERROR) {              
 
  195                      strm->msg == NULL ? 
"compressed data error" : strm->msg);
 
  198     } 
while (strm->avail_out && ret != Z_STREAM_END);
 
  201     state->x.have = had - strm->avail_out;
 
  202     state->x.next = strm->next_out - state->x.have;
 
  205     if (ret == Z_STREAM_END)
 
  220     z_streamp strm = &(state->strm);
 
  227             if (state->how == LOOK)
 
  231             if (
gz_load(state, state->out, state->size << 1, &(state->x.have))
 
  234             state->x.next = state->out;
 
  237             strm->avail_out = state->size << 1;
 
  238             strm->next_out = state->out;
 
  242     } 
while (state->x.have == 0 && (!state->eof || strm->avail_in));
 
  255             n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
 
  256                 (
unsigned)len : state->x.have;
 
  264         else if (state->eof && state->strm.avail_in == 0)
 
  277 int ZEXPORT 
gzread(gzFile file, voidp buf, 
unsigned len)
 
  286     state = (gz_statep)file;
 
  287     strm = &(state->strm);
 
  290     if (state->mode != GZ_READ ||
 
  291             (state->err != Z_OK && state->err != Z_BUF_ERROR))
 
  297         gz_error(state, Z_DATA_ERROR, 
"requested length does not fit in int");
 
  308         if (
gz_skip(state, state->skip) == -1)
 
  317             n = state->x.have > len ? len : state->x.have;
 
  318             memcpy(buf, state->x.next, n);
 
  324         else if (state->eof && strm->avail_in == 0) {
 
  331         else if (state->how == LOOK || len < (state->size << 1)) {
 
  341         else if (state->how == COPY) {      
 
  342             if (
gz_load(state, (
unsigned char *)buf, len, &n) == -1)
 
  348             strm->avail_out = len;
 
  349             strm->next_out = (Bytef *)buf;
 
  358         buf = (
char *)buf + n;
 
  372     unsigned char buf[1];
 
  378     state = (gz_statep)file;
 
  381     if (state->mode != GZ_READ ||
 
  382         (state->err != Z_OK && state->err != Z_BUF_ERROR))
 
  389         return *(state->x.next)++;
 
  393     ret = 
gzread(file, buf, 1);
 
  394     return ret < 1 ? -1 : buf[0];
 
  410     state = (gz_statep)file;
 
  413     if (state->mode != GZ_READ ||
 
  414         (state->err != Z_OK && state->err != Z_BUF_ERROR))
 
  420         if (
gz_skip(state, state->skip) == -1)
 
  429     if (state->x.have == 0) {
 
  431         state->x.next = state->out + (state->size << 1) - 1;
 
  432         state->x.next[0] = c;
 
  439     if (state->x.have == (state->size << 1)) {
 
  440         gz_error(state, Z_DATA_ERROR, 
"out of room to push characters");
 
  445     if (state->x.next == state->out) {
 
  446         unsigned char *src = state->out + state->x.have;
 
  447         unsigned char *dest = state->out + (state->size << 1);
 
  448         while (src > state->out)
 
  450         state->x.next = dest;
 
  454     state->x.next[0] = c;
 
  461 char * ZEXPORT 
gzgets(gzFile file, 
char *buf, 
int len)
 
  469     if (file == NULL || buf == NULL || len < 1)
 
  471     state = (gz_statep)file;
 
  474     if (state->mode != GZ_READ ||
 
  475         (state->err != Z_OK && state->err != Z_BUF_ERROR))
 
  481         if (
gz_skip(state, state->skip) == -1)
 
  489     left = (unsigned)len - 1;
 
  492         if (state->x.have == 0 && 
gz_fetch(state) == -1)
 
  494         if (state->x.have == 0) {       
 
  500         n = state->x.have > left ? left : state->x.have;
 
  501         eol = (
unsigned char *)memchr(state->x.next, 
'\n', n);
 
  503             n = (unsigned)(eol - state->x.next) + 1;
 
  506         memcpy(buf, state->x.next, n);
 
  512     } 
while (left && eol == NULL);
 
  529     state = (gz_statep)file;
 
  533     if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
 
  537     return state->direct;
 
  548         return Z_STREAM_ERROR;
 
  549     state = (gz_statep)file;
 
  552     if (state->mode != GZ_READ)
 
  553         return Z_STREAM_ERROR;
 
  561     err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
 
  564     ret = close(state->fd);
 
  566     return ret ? Z_ERRNO : err;
 
int ZEXPORT gzgetc(gzFile file)
 
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
 
int ZEXPORT gzungetc(int c, gzFile file)
 
local int gz_decomp(gz_statep state)
 
local int gz_fetch(gz_statep state)
 
local int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have)
 
local int gz_look(gz_statep state)
 
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
 
int ZEXPORT gzdirect(gzFile file)
 
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
 
int ZEXPORT gzgetc_(gzFile file)
 
local int gz_skip(gz_statep state, z_off64_t len)
 
int ZEXPORT inflateEnd(z_streamp strm)
 
int ZEXPORT gzclose_r(gzFile file)
 
int ZEXPORT inflate(z_streamp strm, int flush)
 
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *))
 
local int gz_avail(gz_statep state)
 
int ZEXPORT inflateReset(z_streamp strm)