| 506 | |
| 507 | #ifdef HAVE_LIBZ |
| 508 | static bool |
| 509 | tar_write_compressed_data(void *buf, size_t count, bool flush) |
| 510 | { |
| 511 | tar_data->zp->next_in = buf; |
| 512 | tar_data->zp->avail_in = count; |
| 513 | |
| 514 | while (tar_data->zp->avail_in || flush) |
| 515 | { |
| 516 | int r; |
| 517 | |
| 518 | r = deflate(tar_data->zp, flush ? Z_FINISH : Z_NO_FLUSH); |
| 519 | if (r == Z_STREAM_ERROR) |
| 520 | { |
| 521 | tar_set_error("could not compress data"); |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | if (tar_data->zp->avail_out < ZLIB_OUT_SIZE) |
| 526 | { |
| 527 | size_t len = ZLIB_OUT_SIZE - tar_data->zp->avail_out; |
| 528 | |
| 529 | errno = 0; |
| 530 | if (write(tar_data->fd, tar_data->zlibOut, len) != len) |
| 531 | { |
| 532 | /* If write didn't set errno, assume problem is no disk space */ |
| 533 | tar_data->lasterrno = errno ? errno : ENOSPC; |
| 534 | return false; |
| 535 | } |
| 536 | |
| 537 | tar_data->zp->next_out = tar_data->zlibOut; |
| 538 | tar_data->zp->avail_out = ZLIB_OUT_SIZE; |
| 539 | } |
| 540 | |
| 541 | if (r == Z_STREAM_END) |
| 542 | break; |
| 543 | } |
| 544 | |
| 545 | if (flush) |
| 546 | { |
| 547 | /* Reset the stream for writing */ |
| 548 | if (deflateReset(tar_data->zp) != Z_OK) |
| 549 | { |
| 550 | tar_set_error("could not reset compression stream"); |
| 551 | return false; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return true; |
| 556 | } |
| 557 | #endif |
| 558 | |
| 559 | static ssize_t |
no outgoing calls
no test coverage detected