---
name: "zdopen"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/zdopen"
---

# zdopen(3)

open a gzip compressed stream

## NAME

**zopen** – open a gzip compressed stream

## LIBRARY

Compression Library (libz, -lz)

## SYNOPSIS

*FILE* *\**\

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

*FILE* *\**\

**zdopen**(*int fd*, *const char \*mode*);

## DESCRIPTION

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)](/fdopen/3.md). They are wrappers around [zlib(3)](/zlib/3.md) and the standard stream I/O APIs.

The argument *mode* has the same meaning as it does in [fopen(3)](/fopen/3.md).

The **zopen**() and **zdopen**() functions will associate the read, write, seek and close functions of [zlib(3)](/zlib/3.md) 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)](/fopen/3.md) and [fdopen(3)](/fdopen/3.md), 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.

## SEE ALSO

[fdopen(3)](/fdopen/3.md), [fopen(3)](/fopen/3.md), [funopen(3)](/funopen/3.md), [zlib(3)](/zlib/3.md)
