---
name: "zip_open"
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_open"
---

# zip\_open(3)

open zip archive

## NAME

**zip\_open**, **zip\_open\_from\_source** – open zip archive

## LIBRARY

libzip (-lzip)

## SYNOPSIS

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

*zip\_t* *\**\

**zip\_open**(*const char \*path*, *int flags*, *int \*errorp*);

*zip\_t* *\**\

**zip\_open\_from\_source**(*zip\_source\_t \*zs*, *int flags*, *zip\_error\_t \*ze*);

## DESCRIPTION

The **zip\_open**() function opens the zip archive specified by *path* and returns a pointer to a *struct* *zip*, used to manipulate the archive. The *flags* are specified by *or*'ing the following values, or 0 for none of them.

- ZIP\_CHECKCONS

  Perform additional stricter consistency checks on the archive, and error if they fail.

- ZIP\_CREATE

  Create the archive if it does not exist.

- ZIP\_EXCL

  Error if archive already exists.

- ZIP\_TRUNCATE

  If archive exists, ignore its current contents. In other words, handle it the same way as an empty archive.

- ZIP\_RDONLY

  Open archive in read-only mode.

If an error occurs and *errorp* is non-NULL, it will be set to the corresponding error code.

The **zip\_open\_from\_source**() function opens a zip archive encapsulated by the zip\_source *zs* using the provided *flags*. In case of error, the zip\_error *ze* is filled in.

## RETURN VALUES

Upon successful completion **zip\_open**() and **zip\_open\_from\_source**() return a *struct* *zip* pointer. Otherwise, NULL is returned and **zip\_open**() sets *\*errorp* to indicate the error, while **zip\_open\_from**(*source*) sets *ze* to indicate the error.

## EXAMPLES

Here's an example of how you could report errors during **zip\_open**:

```
    zip_t *za;
    int err;
    if ((za = zip_open(name, 0, &err)) == NULL) {
        zip_error_t error;
        zip_error_init_with_code(&error, err);
        fprintf(stderr, "%s: cannot open zip archive '%s': %s\n",
	        progname, name, zip_error_strerror(&error));
        zip_error_fini(&error);
        return -1;
    }
```

## ERRORS

The archive specified by *path* is opened unless:

- \[ZIP\_ER\_EXISTS\]

  The file specified by *path* exists and ZIP\_EXCL is set.

- \[ZIP\_ER\_INCONS\]

  Inconsistencies were found in the file specified by *path*. This error is often caused by specifying ZIP\_CHECKCONS but can also happen without it.

- \[ZIP\_ER\_INVAL\]

  The *path* argument is NULL.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

- \[ZIP\_ER\_NOENT\]

  The file specified by *path* does not exist and ZIP\_CREATE is not set.

- \[ZIP\_ER\_NOZIP\]

  The file specified by *path* is not a zip archive.

- \[ZIP\_ER\_OPEN\]

  The file specified by *path* could not be opened.

- \[ZIP\_ER\_READ\]

  A read error occurred; see *errno* for details.

- \[ZIP\_ER\_SEEK\]

  The file specified by *path* does not allow seeks.

For newly created archives, **zip\_open**() does not try to create the file; this is done when calling [zip\_close(3)](/zip_close/3.md) and any errors, like missing write permissions, will be reported then.

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_close(3)](/zip_close/3.md), [zip\_error\_strerror(3)](/zip_error_strerror/3.md), [zip\_fdopen(3)](/zip_fdopen/3.md), [zip\_source(5)](/zip_source/5.md)

## HISTORY

**zip\_open**() and **zip\_open\_from\_source**() were added in libzip 1.0.

## AUTHORS

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