• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-13-stable/usr.bin/gzip/

Lines Matching refs:lz

292 lz_flush(struct lz_decoder *lz)
294 off_t offs = lz->pos - lz->spos;
299 lz_crc_update(&lz->crc, lz->obuf + lz->spos, size);
300 if (fwrite(lz->obuf + lz->spos, 1, size, lz->fout) != size)
303 lz->wrapped = lz->pos >= lz->dict_size;
304 if (lz->wrapped) {
305 lz->ppos += lz->pos;
306 lz->pos = 0;
308 lz->spos = lz->pos;
313 lz_destroy(struct lz_decoder *lz)
315 if (lz->fin)
316 fclose(lz->fin);
317 if (lz->fout)
318 fclose(lz->fout);
319 free(lz->obuf);
323 lz_create(struct lz_decoder *lz, int fin, int fdout, int dict_size)
325 memset(lz, 0, sizeof(*lz));
327 lz->fin = fdopen(dup(fin), "r");
328 if (lz->fin == NULL)
331 lz->fout = fdopen(dup(fdout), "w");
332 if (lz->fout == NULL)
335 lz->pos = lz->ppos = lz->spos = 0;
336 lz->crc = ~0;
337 lz->dict_size = dict_size;
338 lz->wrapped = false;
340 lz->obuf = malloc(dict_size);
341 if (lz->obuf == NULL)
344 if (lz_rd_create(&lz->rdec, lz->fin) == -1)
348 lz_destroy(lz);
353 lz_peek(const struct lz_decoder *lz, unsigned ahead)
355 off_t diff = lz->pos - ahead - 1;
358 return lz->obuf[diff];
360 if (lz->wrapped)
361 return lz->obuf[lz->dict_size + diff];
367 lz_put(struct lz_decoder *lz, uint8_t b)
369 lz->obuf[lz->pos++] = b;
370 if (lz->dict_size == lz->pos)
371 lz_flush(lz);
375 lz_get_data_position(const struct lz_decoder *lz)
377 return lz->ppos + lz->pos;
381 lz_get_crc(const struct lz_decoder *lz)
383 return lz->crc ^ 0xffffffffU;
409 lz_decode_member(struct lz_decoder *lz)
433 struct lz_range_decoder *rd = &lz->rdec;
439 while (!feof(lz->fin) && !ferror(lz->fin)) {
440 const int pos_state = lz_get_data_position(lz) & POS_STATE_MASK;
443 const uint8_t prev_byte = lz_peek(lz, 0);
448 lz_put(lz, lz_rd_decode_tree(rd, bm, 8));
450 int peek = lz_peek(lz, rep[0]);
451 lz_put(lz, lz_rd_decode_matched(rd, bm, peek));
466 lz_put(lz, lz_peek(lz, rep[0]));
514 lz_flush(lz);
520 if (rep[0] >= lz->dict_size ||
521 (rep[0] >= lz->pos && !lz->wrapped)) {
522 lz_flush(lz);
527 lz_put(lz, lz_peek(lz, rep[0]));
529 lz_flush(lz);
544 struct lz_decoder lz;
547 if (lz_create(&lz, fin, fdout, dict_size) == -1)
550 if (!lz_decode_member(&lz))
556 trailer[i] = (uint8_t)getc(lz.fin);
570 if (crc != lz_get_crc(&lz) || data_size != lz_get_data_position(&lz))
582 rv = ftello(lz.fout);
587 lz_destroy(&lz);