zlib gzclose:如何检测文件是否成功关闭?
zlib gzclose: How to detect a successful file closure?
我用zlib压缩了一个文件。一切正常。操作完成后,我调用 gzclose(file)
刷新并关闭 gzip 文件。根据文档,gzclose
return 是一个 int
,它提供 gzclose
操作的成功或失败。由于可能有很多失败原因,检查每个错误代码对我来说是不可行的。我选择检查操作是否成功并单独处理错误代码。我在我提到的任何文档中都找不到成功 gzclose
的 return 代码。
zlib 函数记录在 zlib.h. You can also find zlib.h formatted a bit in the zlib Manual 中。在那里你会发现:
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
Flushes all pending output if necessary, closes the compressed file
and deallocates the (de)compression state. Note that once file is
closed, you cannot call gzerror
with file, since its structures have
been deallocated. gzclose
must not be called more than once on the
same file, just as free
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 file operation error, Z_MEM_ERROR
if out of memory,
Z_BUF_ERROR
if the last read ended in the middle of a gzip stream, or
Z_OK
on success.
我用zlib压缩了一个文件。一切正常。操作完成后,我调用 gzclose(file)
刷新并关闭 gzip 文件。根据文档,gzclose
return 是一个 int
,它提供 gzclose
操作的成功或失败。由于可能有很多失败原因,检查每个错误代码对我来说是不可行的。我选择检查操作是否成功并单独处理错误代码。我在我提到的任何文档中都找不到成功 gzclose
的 return 代码。
zlib 函数记录在 zlib.h. You can also find zlib.h formatted a bit in the zlib Manual 中。在那里你会发现:
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
Flushes all pending output if necessary, closes the compressed file and deallocates the (de)compression state. Note that once file is closed, you cannot call
gzerror
with file, since its structures have been deallocated.gzclose
must not be called more than once on the same file, just asfree
must not be called more than once on the same allocation.gzclose
will returnZ_STREAM_ERROR
if file is not valid,Z_ERRNO
on a file operation error,Z_MEM_ERROR
if out of memory,Z_BUF_ERROR
if the last read ended in the middle of a gzip stream, orZ_OK
on success.