---
name: "zip_file_extra_field_set"
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_file_extra_field_set"
---

# zip\_file\_extra\_field\_set(3)

set extra field for file in zip

## NAME

**zip\_file\_extra\_field\_set** – set extra field for file in zip

## LIBRARY

libzip (-lzip)

## SYNOPSIS

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

*int*\

**zip\_file\_extra\_field\_set**(*zip\_t \*archive*, *zip\_uint64\_t index*, *zip\_uint16\_t extra\_field\_id*, *zip\_uint16\_t extra\_field\_index*, *const zip\_uint8\_t \*extra\_field\_data*, *zip\_uint16\_t len*, *zip\_flags\_t flags*);

## DESCRIPTION

The **zip\_file\_extra\_field\_set**() function sets the extra field with ID (two-byte signature) *extra\_field\_id* and index *extra\_field\_index* for the file at position *index* in the zip archive. The extra field's data will be set to *extra\_field\_data* and length *len*. If a new entry shall be appended, set *extra\_field\_index* to ZIP\_EXTRA\_FIELD\_NEW.

At least one of the following *flags* must be set:

- ZIP\_FL\_CENTRAL

  Set extra field in the archive's central directory.

- ZIP\_FL\_LOCAL

  Set extra field in the local file headers.

Please note that the extra field IDs 0x0001 (ZIP64 extension), 0x6375 (Infozip UTF-8 comment), and 0x7075 (Infozip UTF-8 file name) can not be set using **zip\_file\_extra\_field\_set**() since they are set by [libzip(3)](/libzip/3.md) automatically when needed.

## 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\_file\_extra\_field\_set**() fails if:

- \[ZIP\_ER\_INVAL\]

  The extra field size is too large (ID and length need 4 bytes; the maximum length of all extra fields for one file combined is 65536 bytes). This error also occurs if *extra\_field\_index* is too large.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

- \[ZIP\_ER\_NOENT\]

  *index* is not a valid file index in *archive*.

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_file\_extra\_field\_delete(3)](/zip_file_extra_field_delete/3.md), [zip\_file\_extra\_field\_get(3)](/zip_file_extra_field_get/3.md), [zip\_file\_extra\_fields\_count(3)](/zip_file_extra_fields_count/3.md)

## HISTORY

**zip\_file\_extra\_field\_set**() was added in libzip 0.11.

## AUTHORS

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