diff options
author | Hans Kristian Rosbach <hk-git@circlestorm.org> | 2017-02-06 13:41:56 +0100 |
---|---|---|
committer | Hans Kristian Rosbach <hk-git@circlestorm.org> | 2017-02-06 13:41:56 +0100 |
commit | 44b2a431afbc6e3654cc5427266b7e1c41cf6e39 (patch) | |
tree | b49934d2178138fd50d677459a875a15eb2ba022 /zlib.h | |
parent | 8fbe9792d3d5e87c33dacb4cc52d57ec0f8de3d6 (diff) |
Add gzfread(), duplicating the interface of fread().
Based on upstream commit 44dfd831d24f9b627ab666cf0973b0dce98fabba
Diffstat (limited to 'zlib.h')
-rw-r--r-- | zlib.h | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1357,7 +1357,32 @@ ZEXTERN int ZEXPORT gzread(gzFile file, void *buf, unsigned len); case. gzread returns the number of uncompressed bytes actually read, less than - len for end of file, or -1 for error. + len for end of file, or -1 for error. If len is too large to fit in an int, + then nothing is read, -1 is returned, and the error state is set to + Z_STREAM_ERROR. +*/ + +ZEXTERN size_t ZEXPORT gzfread (void *buf, size_t size, size_t nitems, gzFile file); +/* + Read up to nitems items of size size from file to buf, otherwise operating + as gzread() does. This duplicates the interface of stdio's fread(), with + size_t request and return types. + + gzfread() returns the number of full items read of size size, or zero if + the end of the file was reached and a full item could not be read, or if + there was an error. gzerror() must be consulted if zero is returned in + order to determine if there was an error. If the multiplication of size and + nitems overflows, i.e. the product does not fit in a size_t, then nothing + is read, zero is returned, and the error state is set to Z_STREAM_ERROR. + + In the event that the end of file is reached and only a partial item is + available at the end, i.e. the remaining uncompressed data length is not a + multiple of size, then the final partial item is nevertheless read into buf + and the end-of-file flag is set. The length of the partial item read is not + provided, but could be inferred from the result of gztell(). This behavior + is the same as the behavior of fread() implementations in common libraries, + but it prevents the direct use of gzfread() to read a concurrently written + file, reseting and retrying on end-of-file, when size is not 1. */ ZEXTERN int ZEXPORT gzwrite(gzFile file, void const *buf, unsigned len); |