diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-30 22:19:12 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-30 22:19:12 -0700 |
commit | 8768ba98af1cf44e9a24fa7dbdf013de4afecf62 (patch) | |
tree | 9391179a68d627b86802b5ef4d6a2d7d4c029204 /gzwrite.c | |
parent | acfc85772a811f4c0efec835a3087b53f83f6079 (diff) | |
download | zlib-8768ba98af1cf44e9a24fa7dbdf013de4afecf62.tar.gz zlib-8768ba98af1cf44e9a24fa7dbdf013de4afecf62.tar.bz2 zlib-8768ba98af1cf44e9a24fa7dbdf013de4afecf62.zip |
Fix gzclose() to return the actual error last encountered.
Diffstat (limited to 'gzwrite.c')
-rw-r--r-- | gzwrite.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -504,7 +504,7 @@ int ZEXPORT gzsetparams(file, level, strategy) | |||
504 | int ZEXPORT gzclose_w(file) | 504 | int ZEXPORT gzclose_w(file) |
505 | gzFile file; | 505 | gzFile file; |
506 | { | 506 | { |
507 | int ret = 0; | 507 | int ret = Z_OK; |
508 | gz_statep state; | 508 | gz_statep state; |
509 | 509 | ||
510 | /* get internal structure */ | 510 | /* get internal structure */ |
@@ -519,17 +519,20 @@ int ZEXPORT gzclose_w(file) | |||
519 | /* check for seek request */ | 519 | /* check for seek request */ |
520 | if (state->seek) { | 520 | if (state->seek) { |
521 | state->seek = 0; | 521 | state->seek = 0; |
522 | ret += gz_zero(state, state->skip); | 522 | if (gz_zero(state, state->skip) == -1) |
523 | ret = state->err; | ||
523 | } | 524 | } |
524 | 525 | ||
525 | /* flush, free memory, and close file */ | 526 | /* flush, free memory, and close file */ |
526 | ret += gz_comp(state, Z_FINISH); | 527 | if (gz_comp(state, Z_FINISH) == -1) |
528 | ret = state->err; | ||
527 | (void)deflateEnd(&(state->strm)); | 529 | (void)deflateEnd(&(state->strm)); |
528 | free(state->out); | 530 | free(state->out); |
529 | free(state->in); | 531 | free(state->in); |
530 | gz_error(state, Z_OK, NULL); | 532 | gz_error(state, Z_OK, NULL); |
531 | free(state->path); | 533 | free(state->path); |
532 | ret += close(state->fd); | 534 | if (close(state->fd) == -1) |
535 | ret = Z_ERRNO; | ||
533 | free(state); | 536 | free(state); |
534 | return ret ? Z_ERRNO : Z_OK; | 537 | return ret; |
535 | } | 538 | } |