-- see zlib.h -- */
(file)
| 631 | |
| 632 | /* -- see zlib.h -- */ |
| 633 | int ZEXPORT gzclose_w(file) |
| 634 | gzFile file; |
| 635 | { |
| 636 | int ret = Z_OK; |
| 637 | gz_statep state; |
| 638 | |
| 639 | /* get internal structure */ |
| 640 | if (file == NULL) |
| 641 | return Z_STREAM_ERROR; |
| 642 | state.file = file; |
| 643 | |
| 644 | /* check that we're writing */ |
| 645 | if (state.state->mode != GZ_WRITE) |
| 646 | return Z_STREAM_ERROR; |
| 647 | |
| 648 | /* check for seek request */ |
| 649 | if (state.state->seek) { |
| 650 | state.state->seek = 0; |
| 651 | if (gz_zero(state, state.state->skip) == -1) |
| 652 | ret = state.state->err; |
| 653 | } |
| 654 | |
| 655 | /* flush, free memory, and close file */ |
| 656 | if (gz_comp(state, Z_FINISH) == -1) |
| 657 | ret = state.state->err; |
| 658 | if (state.state->size) { |
| 659 | if (!state.state->direct) { |
| 660 | (void)deflateEnd(&(state.state->strm)); |
| 661 | free(state.state->out); |
| 662 | } |
| 663 | free(state.state->in); |
| 664 | } |
| 665 | gz_error(state, Z_OK, NULL); |
| 666 | free(state.state->path); |
| 667 | if (close(state.state->fd) == -1) |
| 668 | ret = Z_ERRNO; |
| 669 | free(state.state); |
| 670 | return ret; |
| 671 | } |