Fix gzclose() to return the actual error last encountered.
This commit is contained in:
parent
acfc85772a
commit
8768ba98af
13
gzwrite.c
13
gzwrite.c
@ -504,7 +504,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
|
|||||||
int ZEXPORT gzclose_w(file)
|
int ZEXPORT gzclose_w(file)
|
||||||
gzFile file;
|
gzFile file;
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = Z_OK;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure */
|
||||||
@ -519,17 +519,20 @@ int ZEXPORT gzclose_w(file)
|
|||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->seek) {
|
||||||
state->seek = 0;
|
state->seek = 0;
|
||||||
ret += gz_zero(state, state->skip);
|
if (gz_zero(state, state->skip) == -1)
|
||||||
|
ret = state->err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flush, free memory, and close file */
|
/* flush, free memory, and close file */
|
||||||
ret += gz_comp(state, Z_FINISH);
|
if (gz_comp(state, Z_FINISH) == -1)
|
||||||
|
ret = state->err;
|
||||||
(void)deflateEnd(&(state->strm));
|
(void)deflateEnd(&(state->strm));
|
||||||
free(state->out);
|
free(state->out);
|
||||||
free(state->in);
|
free(state->in);
|
||||||
gz_error(state, Z_OK, NULL);
|
gz_error(state, Z_OK, NULL);
|
||||||
free(state->path);
|
free(state->path);
|
||||||
ret += close(state->fd);
|
if (close(state->fd) == -1)
|
||||||
|
ret = Z_ERRNO;
|
||||||
free(state);
|
free(state);
|
||||||
return ret ? Z_ERRNO : Z_OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
2
zlib.h
2
zlib.h
@ -1446,7 +1446,7 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
|||||||
must not be called more than once on the same allocation.
|
must not be called more than once on the same allocation.
|
||||||
|
|
||||||
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
|
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
|
||||||
file operation error, or Z_OK on success.
|
file operation error, Z_MEM_ERROR if out of memory, or Z_OK on success.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
|
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
|
||||||
|
Loading…
Reference in New Issue
Block a user