Manpages - archive_write_open.3
Streaming Archive Library (libarchive, -larchive)
Freeze the settings, open the archive, and prepare for writing entries. This is the most generic form of this function, which accepts pointers to three callback functions which will be invoked by the compression layer to write the constructed archive. This does not alter the default archive padding.
Same as
with an additional fourth free callback. This function should be preferred to
A convenience form of
that accepts a file descriptor. The
function is safe for use with tape drives or other block-oriented devices.
A convenience form of
that accepts a
pointer. Note that
is not safe for writing to tape drives or other devices that require correct blocking.
A deprecated synonym for
A convenience form of
that accepts a filename. A NULL argument indicates that the output should be written to standard output; an argument of
will open a file with that name. If you have not invoked
then
will adjust the last-block padding depending on the file: it will enable padding when writing to standard output or to a character or block device node, it will disable padding otherwise. You can override this by manually invoking
before calling
The
function is safe for use with tape drives or other block-oriented devices.
A convenience form of
that accepts a pointer to a block of memory that will receive the archive. The final
argument points to a variable that will be updated after each write to reflect how much of the buffer is currently in use. You should be careful to ensure that this variable remains allocated until after the archive is closed. This function will disable padding unless you have specifically set the block size.
More information about the
object and the overall design of the library can be found in the
overview.
Note that the convenience forms above vary in how they block the output. See
if you need to control the block size used for writes or the end-of-file padding behavior.
To use this library, you will need to define and register callback functions that will be invoked to write data to the resulting archive. These functions are registered by calling
The open callback is invoked by
It should return
if the underlying file or data source is successfully opened. If the open fails, it should call
to register an error code and message and return
Please note that if open fails, close is not called and resources must be freed inside the open callback or with the free callback.
The write callback is invoked whenever the library needs to write raw bytes to the archive. For correct blocking, each call to the write callback function should translate into a single
system call. This is especially critical when writing archives to tape drives. On success, the write callback should return the number of bytes actually written. On error, the callback should invoke
to register an error code and message and return -1.
The close callback is invoked by archive_close when the archive processing is complete. If the open callback fails, the close callback is not invoked. The callback should return
on success. On failure, the callback should invoke
to register an error code and message and return
The free callback is always invoked on archive_free. The return code of this callback is not processed.
Note that if the client-provided write callback function returns a non-zero value, that error will be propagated back to the caller through whatever API function resulted in that call, which may include
or
The client callback can call
to provide values that can then be retrieved by
and
These functions return
on success, or
Detailed error codes and textual descriptions are available from the
and
functions.