[Zlib-devel] zlib 1.2.4 released!

Mark Adler madler at alumni.caltech.edu
Sat Mar 20 13:59:37 EDT 2010


On Mar 18, 2010, at 5:38 PM, John Bowler wrote:
> gzclose(gzFile) calls close(state->fd), and this is expected (as zlib.h documents it), so the whole thing gets a lot more complicated, particularly given the comments in zlib.h about what happens if the gzdopen fails.
> 
> Maybe it is better to have gznativeopen(HFILE, char*) and have that *not* close the HFILE ever, on the basis that only the creator of an object should ever destroy it, or is this getting too complicated...

The reason gzclose() closes the gzdopen() file descriptor is because that's what fdopen() / fclose() does.  The gz* functions are intended to emulate the stdio functions.  From the fdopen() man page:

     The fdopen() function associates a stream with the existing file descrip-
     tor, fildes.  The mode of the stream must be compatible with the mode of
     the file descriptor.  When the stream is closed via fclose(3), fildes is
     closed also.

I supposed I could add a variant on the gzdopen() function that let's gzclose() know to not close the descriptor.   However I'm not clear on how you can use the file descriptor in read() and write(), but run into problems if you use close() on it.

Mark





More information about the Zlib-devel mailing list