---
name: "zip_close"
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_close"
---

# zip\_close(3)

close zip archive

## NAME

**zip\_close** – close zip archive

## LIBRARY

libzip (-lzip)

## SYNOPSIS

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

*int*\

**zip\_close**(*zip\_t \*archive*);

## DESCRIPTION

The **zip\_close**() function writes any changes made to *archive* to disk. If *archive* contains no files, the file is completely removed (no empty archive is written), unless the archive flag ZIP\_AFL\_CREATE\_OR\_KEEP\_FILE\_FOR\_EMPTY\_ARCHIVE is set. If successful, *archive* is freed. Otherwise *archive* is left unchanged and must still be freed.

To close and free a zip archive without saving changes, use [zip\_discard(3)](/zip_discard/3.md).

Progress updates for GUIs can be implemented using [zip\_register\_progress\_callback\_with\_state(3)](/zip_register_progress_callback_with_state/3.md). Cancelling the write of an archive during **zip\_close** can be implemented using [zip\_register\_cancel\_callback\_with\_state(3)](/zip_register_cancel_callback_with_state/3.md).

## RETURN VALUES

Upon successful completion 0 is returned. Otherwise, -1 is returned and the error code in *archive* is set to indicate the error.

## ERRORS

**zip\_close**() will fail if:

- \[ZIP\_ER\_EOF\]

  Unexpected end-of-file found while reading from a file.

- \[ZIP\_ER\_INTERNAL\]

  The callback function of an added or replaced file returned an error but failed to report which.

- \[ZIP\_ER\_INVAL\]

  The *path* argument is NULL.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

- \[ZIP\_ER\_NOZIP\]

  File is not a zip archive.

- \[ZIP\_ER\_READ\]

  A file read failed.

- \[ZIP\_ER\_RENAME\]

  A temporary file could not be renamed to its final name.

- \[ZIP\_ER\_SEEK\]

  A file seek failed.

- \[ZIP\_ER\_TMPOPEN\]

  A temporary file could not be created.

- \[ZIP\_ER\_WRITE\]

  A file write failed.

- \[ZIP\_ER\_ZLIB\]

  An error occurred while (de)compressing a stream with [zlib(3)](/zlib/3.md).

Additionally, any errors returned by the callback function for added or replaced files will be passed back.

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_discard(3)](/zip_discard/3.md), [zip\_fdopen(3)](/zip_fdopen/3.md), [zip\_get\_error(3)](/zip_get_error/3.md), [zip\_open(3)](/zip_open/3.md), [zip\_register\_cancel\_callback\_with\_state(3)](/zip_register_cancel_callback_with_state/3.md), [zip\_register\_progress\_callback\_with\_state(3)](/zip_register_progress_callback_with_state/3.md), [zip\_set\_archive\_flag(3)](/zip_set_archive_flag/3.md), [zip\_strerror(3)](/zip_strerror/3.md)

## HISTORY

**zip\_close**() was added in libzip 0.6.

## AUTHORS

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

## CAVEATS

Please note that all indices, [zip\_stat(3)](/zip_stat/3.md) information and other data about the archive is invalid after **zip\_close**. When you open the same file again, it will be a completely new *zip\_t* structure.
