| 628 | } |
| 629 | |
| 630 | static Walfile |
| 631 | tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_size) |
| 632 | { |
| 633 | char *tmppath; |
| 634 | |
| 635 | tar_clear_error(); |
| 636 | |
| 637 | if (tar_data->fd < 0) |
| 638 | { |
| 639 | /* |
| 640 | * We open the tar file only when we first try to write to it. |
| 641 | */ |
| 642 | tar_data->fd = open(tar_data->tarfilename, |
| 643 | O_WRONLY | O_CREAT | PG_BINARY, |
| 644 | pg_file_create_mode); |
| 645 | if (tar_data->fd < 0) |
| 646 | { |
| 647 | tar_data->lasterrno = errno; |
| 648 | return NULL; |
| 649 | } |
| 650 | |
| 651 | #ifdef HAVE_LIBZ |
| 652 | if (tar_data->compression) |
| 653 | { |
| 654 | tar_data->zp = (z_streamp) pg_malloc(sizeof(z_stream)); |
| 655 | tar_data->zp->zalloc = Z_NULL; |
| 656 | tar_data->zp->zfree = Z_NULL; |
| 657 | tar_data->zp->opaque = Z_NULL; |
| 658 | tar_data->zp->next_out = tar_data->zlibOut; |
| 659 | tar_data->zp->avail_out = ZLIB_OUT_SIZE; |
| 660 | |
| 661 | /* |
| 662 | * Initialize deflation library. Adding the magic value 16 to the |
| 663 | * default 15 for the windowBits parameter makes the output be |
| 664 | * gzip instead of zlib. |
| 665 | */ |
| 666 | if (deflateInit2(tar_data->zp, tar_data->compression, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK) |
| 667 | { |
| 668 | pg_free(tar_data->zp); |
| 669 | tar_data->zp = NULL; |
| 670 | tar_set_error("could not initialize compression library"); |
| 671 | return NULL; |
| 672 | } |
| 673 | } |
| 674 | #endif |
| 675 | |
| 676 | /* There's no tar header itself, the file starts with regular files */ |
| 677 | } |
| 678 | |
| 679 | if (tar_data->currentfile != NULL) |
| 680 | { |
| 681 | tar_set_error("implementation error: tar files can't have more than one open file"); |
| 682 | return NULL; |
| 683 | } |
| 684 | |
| 685 | tar_data->currentfile = pg_malloc0(sizeof(TarMethodFile)); |
| 686 | |
| 687 | tmppath = tar_get_file_name(pathname, temp_suffix); |
nothing calls this directly
no test coverage detected