xref: /freebsd/sys/contrib/zstd/zlibWrapper/gzclose.c (revision 9cbefe25d46756f342c7dd3d174d2d1103808f21)
10c16b537SWarner Losh /* gzclose.c contains minimal changes required to be compiled with zlibWrapper:
20c16b537SWarner Losh  * - gz_statep was converted to union to work with -Wstrict-aliasing=1      */
30c16b537SWarner Losh 
40c16b537SWarner Losh /* gzclose.c -- zlib gzclose() function
50c16b537SWarner Losh  * Copyright (C) 2004, 2010 Mark Adler
60c16b537SWarner Losh  * For conditions of distribution and use, see http://www.zlib.net/zlib_license.html
70c16b537SWarner Losh  */
80c16b537SWarner Losh 
90c16b537SWarner Losh #include "gzguts.h"
100c16b537SWarner Losh 
110c16b537SWarner Losh /* gzclose() is in a separate file so that it is linked in only if it is used.
120c16b537SWarner Losh    That way the other gzclose functions can be used instead to avoid linking in
130c16b537SWarner Losh    unneeded compression or decompression routines. */
gzclose(file)140c16b537SWarner Losh int ZEXPORT gzclose(file)
150c16b537SWarner Losh     gzFile file;
160c16b537SWarner Losh {
170c16b537SWarner Losh #ifndef NO_GZCOMPRESS
180c16b537SWarner Losh     gz_statep state;
190c16b537SWarner Losh 
200c16b537SWarner Losh     if (file == NULL)
210c16b537SWarner Losh         return Z_STREAM_ERROR;
22*9cbefe25SConrad Meyer     state.file = file;
230c16b537SWarner Losh 
240c16b537SWarner Losh     return state.state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
250c16b537SWarner Losh #else
260c16b537SWarner Losh     return gzclose_r(file);
270c16b537SWarner Losh #endif
280c16b537SWarner Losh }
29