zopen(3)

zopen3

Open a gzip compressed stream

Usage

FILE *

zopen(const char *path, const char *mode);

FILE *

zdopen(int fd, const char *mode);

Library

Compression Library (libz, -lz)

Overview

The zopen() function opens a gzip file whose name is the string pointed to by path and returns a stream which can be used to access the uncompressed contents of the file. The zdopen() variant takes a gzip file referenced by the file descriptor fd, analogous to fdopen(3). They are wrappers around zlib(3) and the standard stream I/O APIs.

The argument mode has the same meaning as it does in fopen(3).

The zopen() and zdopen() functions will associate the read, write, seek and close functions of zlib(3) with the returned stream.

Return values

Upon successful completion zopen() and zdopen() return a FILE pointer. Otherwise, NULL is returned and the global variable errno is set to indicate the error.

Errors

In addition to the errors documented for fopen(3) and fdopen(3), the functions may also fail for:

[ENOMEM]

Insufficient memory is available.

Compatibility

The implementation of zopen() function first appeared in NetBSD 1.6 and FreeBSD 4.5. zdopen() first appeared in FreeBSD 13.0. These functions may not be portable to systems other than FreeBSD.

Releases

25 releases since FreeBSD 11.0-RELEASE; the text changed 11 times.

  1. 11.0
  2. 11.1
  3. 11.2
  4. 11.3
  5. 11.4
  6. 12.0
  7. 12.1
  8. 12.2
  9. 12.3
  10. 12.4
  11. 13.0–13.2
  12. 13.3–16.0

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.