-- see zlib.h -- */
| 665 | |
| 666 | /* -- see zlib.h -- */ |
| 667 | int ZEXPORT gzclose_w(gzFile file) { |
| 668 | int ret = Z_OK; |
| 669 | gz_statep state; |
| 670 | |
| 671 | /* get internal structure */ |
| 672 | if (file == NULL) |
| 673 | return Z_STREAM_ERROR; |
| 674 | state = (gz_statep)file; |
| 675 | |
| 676 | /* check that we're writing */ |
| 677 | if (state->mode != GZ_WRITE) |
| 678 | return Z_STREAM_ERROR; |
| 679 | |
| 680 | /* check for seek request */ |
| 681 | if (state->skip && gz_zero(state) == -1) |
| 682 | ret = state->err; |
| 683 | |
| 684 | /* flush, free memory, and close file */ |
| 685 | if (gz_comp(state, Z_FINISH) == -1) |
| 686 | ret = state->err; |
| 687 | if (state->size) { |
| 688 | if (!state->direct) { |
| 689 | (void)deflateEnd(&(state->strm)); |
| 690 | free(state->out); |
| 691 | } |
| 692 | free(state->in); |
| 693 | } |
| 694 | gz_error(state, Z_OK, NULL); |
| 695 | free(state->path); |
| 696 | if (close(state->fd) == -1) |
| 697 | ret = Z_ERRNO; |
| 698 | free(state); |
| 699 | return ret; |
| 700 | } |