---
name: "archive_write_data"
section: "3"
platform: "macos"
package: "libarchive"
version: "167.120.3"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/archive_write_data"
---

# archive\_write\_data(3)

functions for creating archives

## NAME

**archive\_write\_data**, **archive\_write\_data\_block** - functions for creating archives

## LIBRARY

Streaming Archive Library (libarchive, -larchive)

## SYNOPSIS

**#include \<archive.h\>**\
 *la\_ssize\_t*\
 **archive\_write\_data**(*struct archive \**, *const void \**, *size\_t*);\
 *la\_ssize\_t*\
 **archive\_write\_data\_block**(*struct archive \**, *const void \**, *size\_t size*, *int64\_t offset*);

## DESCRIPTION

- **archive\_write\_data**()

  Write data corresponding to the header just written.

- **archive\_write\_data\_block**()

  Write data corresponding to the header just written. This is like **archive\_write\_data**() except that it performs a seek on the file being written to the specified offset before writing the data. This is useful when restoring sparse files from archive formats that support sparse files. Returns number of bytes written or -1 on error. (Note: This is currently not supported for Tn archive\_write handles, only for Tn archive\_write\_disk handles.

## RETURN VALUES

This function returns the number of bytes actually written, or a negative error code on error.

## ERRORS

Detailed error codes and textual descriptions are available from the **archive\_errno**() and **archive\_error\_string**() functions.

## BUGS

In libarchive 3.x, this function sometimes returns zero on success instead of returning the number of bytes written. Specifically, this occurs when writing to an Vt archive\_write\_disk handle. Clients should treat any value less than zero as an error and consider any non-negative value as success.

## SEE ALSO

[**tar**(1)](/tar/1.md), [**archive\_write\_finish\_entry**(3)](/archive_write_finish_entry/3.md), [**archive\_write\_set\_options**(3)](/archive_write_set_options/3.md), [**libarchive**(3)](/libarchive/3.md), [**cpio**(5)](/cpio/5.md), [**mtree**(5)](/mtree/5.md), [**tar**(5)](/tar/5.md)
