---
name: "zip_fopen"
section: "3"
platform: "linux"
package: "libzip"
version: "1.11.4-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/zip_fopen"
---

# zip\_fopen(3)

open file in zip archive for reading

## NAME

**zip\_fopen**, **zip\_fopen\_index** – open file in zip archive for reading

## LIBRARY

libzip (-lzip)

## SYNOPSIS

**#include \<zip.h\>**

*zip\_file\_t* *\**\

**zip\_fopen**(*zip\_t \*archive*, *const char \*fname*, *zip\_flags\_t flags*);

*zip\_file\_t* *\**\

**zip\_fopen\_index**(*zip\_t \*archive*, *zip\_uint64\_t index*, *zip\_flags\_t flags*);

## DESCRIPTION

The **zip\_fopen**() function opens the file name *fname* in *archive*. The *flags* argument specifies how the name lookup should be done, according to the values are described in [zip\_name\_locate(3)](/zip_name_locate/3.md). Also, the following values may be *or*'ed to it.

- ZIP\_FL\_COMPRESSED

  Read the compressed data. Otherwise the data is uncompressed by **zip\_fread**().

- ZIP\_FL\_UNCHANGED

  Read the original data from the zip archive, ignoring any changes made to the file; this is not supported by all data sources.

The **zip\_fopen\_index**() function opens the file at position *index*.

If encrypted data is encountered, the functions call [zip\_fopen\_encrypted(3)](/zip_fopen_encrypted/3.md) or [zip\_fopen\_index\_encrypted(3)](/zip_fopen_index_encrypted/3.md) respectively, using the default password set with [zip\_set\_default\_password(3)](/zip_set_default_password/3.md).

## RETURN VALUES

Upon successful completion, a *struct* *zip\_file* pointer is returned. Otherwise, NULL is returned and the error code in *archive* is set to indicate the error.

## ERRORS

- \[ZIP\_ER\_CHANGED\]

  The file data has been changed and the data source does not support rereading data.

- \[ZIP\_ER\_COMPNOTSUPP\]

  The compression method used is not supported.

- \[ZIP\_ER\_ENCRNOTSUPP\]

  The encryption method used is not supported.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

- \[ZIP\_ER\_NOPASSWD\]

  The file is encrypted, but no password has been provided.

- \[ZIP\_ER\_READ\]

  A file read error occurred.

- \[ZIP\_ER\_SEEK\]

  A file seek error occurred.

- \[ZIP\_ER\_WRONGPASSWD\]

  The provided password does not match the password used for encryption. Note that some incorrect passwords are not detected by the check done by **zip\_fopen**().

- \[ZIP\_ER\_ZLIB\]

  Initializing the zlib stream failed.

The function **zip\_fopen**() may also fail and set *zip\_err* for any of the errors specified for the routine [zip\_name\_locate(3)](/zip_name_locate/3.md).

The function **zip\_fopen\_index**() may also fail with ZIP\_ER\_INVAL if *index* is invalid.

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_fclose(3)](/zip_fclose/3.md), [zip\_fread(3)](/zip_fread/3.md), [zip\_fseek(3)](/zip_fseek/3.md), [zip\_get\_num\_entries(3)](/zip_get_num_entries/3.md), [zip\_name\_locate(3)](/zip_name_locate/3.md), [zip\_set\_default\_password(3)](/zip_set_default_password/3.md)

## HISTORY

**zip\_fopen**() and **zip\_fopen\_index**() were added in libzip 1.0.

## AUTHORS

Dieter Baron ⟨*dillo@nih.at*⟩ and Thomas Klausner ⟨*wiz@gatalith.at*⟩
