Lines Matching defs:lz
290 lz_flush(struct lz_decoder *lz)
292 off_t offs = lz->pos - lz->spos;
297 lz_crc_update(&lz->crc, lz->obuf + lz->spos, size);
298 if (!tflag && fwrite(lz->obuf + lz->spos, 1, size, lz->fout) != size)
301 lz->wrapped = lz->pos >= lz->dict_size;
302 if (lz->wrapped) {
303 lz->ppos += lz->pos;
304 lz->pos = 0;
306 lz->spos = lz->pos;
311 lz_destroy(struct lz_decoder *lz)
313 if (lz->fin)
314 fclose(lz->fin);
315 if (lz->fout)
316 fclose(lz->fout);
317 free(lz->obuf);
321 lz_create(struct lz_decoder *lz, int fin, int fdout, int dict_size)
323 memset(lz, 0, sizeof(*lz));
325 lz->fin = fdopen(dup(fin), "r");
326 if (lz->fin == NULL)
329 lz->fout = fdopen(dup(fdout), "w");
330 if (lz->fout == NULL)
333 lz->pos = lz->ppos = lz->spos = 0;
334 lz->crc = ~0;
335 lz->dict_size = dict_size;
336 lz->wrapped = false;
338 lz->obuf = malloc(dict_size);
339 if (lz->obuf == NULL)
342 if (lz_rd_create(&lz->rdec, lz->fin) == -1)
346 lz_destroy(lz);
351 lz_peek(const struct lz_decoder *lz, unsigned ahead)
353 off_t diff = lz->pos - ahead - 1;
356 return lz->obuf[diff];
358 if (lz->wrapped)
359 return lz->obuf[lz->dict_size + diff];
365 lz_put(struct lz_decoder *lz, uint8_t b)
367 lz->obuf[lz->pos++] = b;
368 if (lz->dict_size == lz->pos)
369 lz_flush(lz);
373 lz_get_data_position(const struct lz_decoder *lz)
375 return lz->ppos + lz->pos;
379 lz_get_crc(const struct lz_decoder *lz)
381 return lz->crc ^ 0xffffffffU;
407 lz_decode_member(struct lz_decoder *lz)
431 struct lz_range_decoder *rd = &lz->rdec;
437 while (!feof(lz->fin) && !ferror(lz->fin)) {
438 const int pos_state = lz_get_data_position(lz) & POS_STATE_MASK;
441 const uint8_t prev_byte = lz_peek(lz, 0);
446 lz_put(lz, lz_rd_decode_tree(rd, bm, 8));
448 int peek = lz_peek(lz, rep[0]);
449 lz_put(lz, lz_rd_decode_matched(rd, bm, peek));
464 lz_put(lz, lz_peek(lz, rep[0]));
512 lz_flush(lz);
518 if (rep[0] >= lz->dict_size ||
519 (rep[0] >= lz->pos && !lz->wrapped)) {
520 lz_flush(lz);
525 lz_put(lz, lz_peek(lz, rep[0]));
527 lz_flush(lz);
542 struct lz_decoder lz;
545 if (lz_create(&lz, fin, fdout, dict_size) == -1)
548 if (!lz_decode_member(&lz))
554 trailer[i] = (uint8_t)getc(lz.fin);
568 if (crc != lz_get_crc(&lz) || data_size != lz_get_data_position(&lz))
580 rv = ftello(lz.fout);
585 lz_destroy(&lz);