Blame libarchive/archive_write_open.3

Packit 08bd4c
.\" Copyright (c) 2003-2011 Tim Kientzle
Packit 08bd4c
.\" All rights reserved.
Packit 08bd4c
.\"
Packit 08bd4c
.\" Redistribution and use in source and binary forms, with or without
Packit 08bd4c
.\" modification, are permitted provided that the following conditions
Packit 08bd4c
.\" are met:
Packit 08bd4c
.\" 1. Redistributions of source code must retain the above copyright
Packit 08bd4c
.\"    notice, this list of conditions and the following disclaimer.
Packit 08bd4c
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit 08bd4c
.\"    notice, this list of conditions and the following disclaimer in the
Packit 08bd4c
.\"    documentation and/or other materials provided with the distribution.
Packit 08bd4c
.\"
Packit 08bd4c
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit 08bd4c
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 08bd4c
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 08bd4c
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit 08bd4c
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 08bd4c
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 08bd4c
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 08bd4c
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 08bd4c
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 08bd4c
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 08bd4c
.\" SUCH DAMAGE.
Packit 08bd4c
.\"
Packit 08bd4c
.\" $FreeBSD$
Packit 08bd4c
.\"
Packit 08bd4c
.Dd February 2, 2012
Packit 08bd4c
.Dt ARCHIVE_WRITE_OPEN 3
Packit 08bd4c
.Os
Packit 08bd4c
.Sh NAME
Packit 08bd4c
.Nm archive_write_open ,
Packit 08bd4c
.Nm archive_write_open_fd ,
Packit 08bd4c
.Nm archive_write_open_FILE ,
Packit 08bd4c
.Nm archive_write_open_filename ,
Packit 08bd4c
.Nm archive_write_open_memory
Packit 08bd4c
.Nd functions for creating archives
Packit 08bd4c
.Sh LIBRARY
Packit 08bd4c
Streaming Archive Library (libarchive, -larchive)
Packit 08bd4c
.Sh SYNOPSIS
Packit 08bd4c
.In archive.h
Packit 08bd4c
.Ft int
Packit 08bd4c
.Fo archive_write_open
Packit 08bd4c
.Fa "struct archive *"
Packit 08bd4c
.Fa "void *client_data"
Packit 08bd4c
.Fa "archive_open_callback *"
Packit 08bd4c
.Fa "archive_write_callback *"
Packit 08bd4c
.Fa "archive_close_callback *"
Packit 08bd4c
.Fc
Packit 08bd4c
.Ft int
Packit 08bd4c
.Fn archive_write_open_fd "struct archive *" "int fd"
Packit 08bd4c
.Ft int
Packit 08bd4c
.Fn archive_write_open_FILE "struct archive *" "FILE *file"
Packit 08bd4c
.Ft int
Packit 08bd4c
.Fn archive_write_open_filename "struct archive *" "const char *filename"
Packit 08bd4c
.Ft int
Packit 08bd4c
.Fo archive_write_open_memory
Packit 08bd4c
.Fa "struct archive *"
Packit 08bd4c
.Fa "void *buffer"
Packit 08bd4c
.Fa "size_t bufferSize"
Packit 08bd4c
.Fa "size_t *outUsed"
Packit 08bd4c
.Fc
Packit 08bd4c
.Sh DESCRIPTION
Packit 08bd4c
.Bl -tag -width indent
Packit 08bd4c
.It Fn archive_write_open
Packit 08bd4c
Freeze the settings, open the archive, and prepare for writing entries.
Packit 08bd4c
This is the most generic form of this function, which accepts
Packit 08bd4c
pointers to three callback functions which will be invoked by
Packit 08bd4c
the compression layer to write the constructed archive.
Packit 08bd4c
This does not alter the default archive padding.
Packit 08bd4c
.It Fn archive_write_open_fd
Packit 08bd4c
A convenience form of
Packit 08bd4c
.Fn archive_write_open
Packit 08bd4c
that accepts a file descriptor.
Packit 08bd4c
The
Packit 08bd4c
.Fn archive_write_open_fd
Packit 08bd4c
function is safe for use with tape drives or other
Packit 08bd4c
block-oriented devices.
Packit 08bd4c
.It Fn archive_write_open_FILE
Packit 08bd4c
A convenience form of
Packit 08bd4c
.Fn archive_write_open
Packit 08bd4c
that accepts a
Packit 08bd4c
.Ft "FILE *"
Packit 08bd4c
pointer.
Packit 08bd4c
Note that
Packit 08bd4c
.Fn archive_write_open_FILE
Packit 08bd4c
is not safe for writing to tape drives or other devices
Packit 08bd4c
that require correct blocking.
Packit 08bd4c
.It Fn archive_write_open_file
Packit 08bd4c
A deprecated synonym for
Packit 08bd4c
.Fn archive_write_open_filename .
Packit 08bd4c
.It Fn archive_write_open_filename
Packit 08bd4c
A convenience form of
Packit 08bd4c
.Fn archive_write_open
Packit 08bd4c
that accepts a filename.
Packit 08bd4c
A NULL argument indicates that the output should be written to standard output;
Packit 08bd4c
an argument of
Packit 08bd4c
.Dq -
Packit 08bd4c
will open a file with that name.
Packit 08bd4c
If you have not invoked
Packit 08bd4c
.Fn archive_write_set_bytes_in_last_block ,
Packit 08bd4c
then
Packit 08bd4c
.Fn archive_write_open_filename
Packit 08bd4c
will adjust the last-block padding depending on the file:
Packit 08bd4c
it will enable padding when writing to standard output or
Packit 08bd4c
to a character or block device node, it will disable padding otherwise.
Packit 08bd4c
You can override this by manually invoking
Packit 08bd4c
.Fn archive_write_set_bytes_in_last_block
Packit 08bd4c
before calling
Packit 08bd4c
.Fn archive_write_open .
Packit 08bd4c
The
Packit 08bd4c
.Fn archive_write_open_filename
Packit 08bd4c
function is safe for use with tape drives or other
Packit 08bd4c
block-oriented devices.
Packit 08bd4c
.It Fn archive_write_open_memory
Packit 08bd4c
A convenience form of
Packit 08bd4c
.Fn archive_write_open
Packit 08bd4c
that accepts a pointer to a block of memory that will receive
Packit 08bd4c
the archive.
Packit 08bd4c
The final
Packit 08bd4c
.Ft "size_t *"
Packit 08bd4c
argument points to a variable that will be updated
Packit 08bd4c
after each write to reflect how much of the buffer
Packit 08bd4c
is currently in use.
Packit 08bd4c
You should be careful to ensure that this variable
Packit 08bd4c
remains allocated until after the archive is
Packit 08bd4c
closed.
Packit 08bd4c
This function will disable padding unless you
Packit 08bd4c
have specifically set the block size.
Packit 08bd4c
.El
Packit 08bd4c
More information about the
Packit 08bd4c
.Va struct archive
Packit 08bd4c
object and the overall design of the library can be found in the
Packit 08bd4c
.Xr libarchive 3
Packit 08bd4c
overview.
Packit 08bd4c
.Pp
Packit 08bd4c
Note that the convenience forms above vary in how
Packit 08bd4c
they block the output.
Packit 08bd4c
See
Packit 08bd4c
.Xr archive_write_blocksize 3
Packit 08bd4c
if you need to control the block size used for writes
Packit 08bd4c
or the end-of-file padding behavior.
Packit 08bd4c
.\"
Packit 08bd4c
.Sh CLIENT CALLBACKS
Packit 08bd4c
To use this library, you will need to define and register
Packit 08bd4c
callback functions that will be invoked to write data to the
Packit 08bd4c
resulting archive.
Packit 08bd4c
These functions are registered by calling
Packit 08bd4c
.Fn archive_write_open :
Packit 08bd4c
.Bl -item -offset indent
Packit 08bd4c
.It
Packit 08bd4c
.Ft typedef int
Packit 08bd4c
.Fn archive_open_callback "struct archive *" "void *client_data"
Packit 08bd4c
.El
Packit 08bd4c
.Pp
Packit 08bd4c
The open callback is invoked by
Packit 08bd4c
.Fn archive_write_open .
Packit 08bd4c
It should return
Packit 08bd4c
.Cm ARCHIVE_OK
Packit 08bd4c
if the underlying file or data source is successfully
Packit 08bd4c
opened.
Packit 08bd4c
If the open fails, it should call
Packit 08bd4c
.Fn archive_set_error
Packit 08bd4c
to register an error code and message and return
Packit 08bd4c
.Cm ARCHIVE_FATAL .
Packit 08bd4c
.Bl -item -offset indent
Packit 08bd4c
.It
Packit 08bd4c
.Ft typedef la_ssize_t
Packit 08bd4c
.Fo archive_write_callback
Packit 08bd4c
.Fa "struct archive *"
Packit 08bd4c
.Fa "void *client_data"
Packit 08bd4c
.Fa "const void *buffer"
Packit 08bd4c
.Fa "size_t length"
Packit 08bd4c
.Fc
Packit 08bd4c
.El
Packit 08bd4c
.Pp
Packit 08bd4c
The write callback is invoked whenever the library
Packit 08bd4c
needs to write raw bytes to the archive.
Packit 08bd4c
For correct blocking, each call to the write callback function
Packit 08bd4c
should translate into a single
Packit 08bd4c
.Xr write 2
Packit 08bd4c
system call.
Packit 08bd4c
This is especially critical when writing archives to tape drives.
Packit 08bd4c
On success, the write callback should return the
Packit 08bd4c
number of bytes actually written.
Packit 08bd4c
On error, the callback should invoke
Packit 08bd4c
.Fn archive_set_error
Packit 08bd4c
to register an error code and message and return -1.
Packit 08bd4c
.Bl -item -offset indent
Packit 08bd4c
.It
Packit 08bd4c
.Ft typedef int
Packit 08bd4c
.Fn archive_close_callback "struct archive *" "void *client_data"
Packit 08bd4c
.El
Packit 08bd4c
.Pp
Packit 08bd4c
The close callback is invoked by archive_close when
Packit 08bd4c
the archive processing is complete.
Packit 08bd4c
The callback should return
Packit 08bd4c
.Cm ARCHIVE_OK
Packit 08bd4c
on success.
Packit 08bd4c
On failure, the callback should invoke
Packit 08bd4c
.Fn archive_set_error
Packit 08bd4c
to register an error code and message and
Packit 08bd4c
return
Packit 08bd4c
.Cm ARCHIVE_FATAL.
Packit 08bd4c
.Pp
Packit 08bd4c
Note that if the client-provided write callback function
Packit 08bd4c
returns a non-zero value, that error will be propagated back to the caller
Packit 08bd4c
through whatever API function resulted in that call, which
Packit 08bd4c
may include
Packit 08bd4c
.Fn archive_write_header ,
Packit 08bd4c
.Fn archive_write_data ,
Packit 08bd4c
.Fn archive_write_close ,
Packit 08bd4c
.Fn archive_write_finish ,
Packit 08bd4c
or
Packit 08bd4c
.Fn archive_write_free .
Packit 08bd4c
The client callback can call
Packit 08bd4c
.Fn archive_set_error
Packit 08bd4c
to provide values that can then be retrieved by
Packit 08bd4c
.Fn archive_errno
Packit 08bd4c
and
Packit 08bd4c
.Fn archive_error_string .
Packit 08bd4c
.\" .Sh EXAMPLE
Packit 08bd4c
.Sh RETURN VALUES
Packit 08bd4c
These functions return
Packit 08bd4c
.Cm ARCHIVE_OK
Packit 08bd4c
on success, or
Packit 08bd4c
.Cm ARCHIVE_FATAL .
Packit 08bd4c
.\"
Packit 08bd4c
.Sh ERRORS
Packit 08bd4c
Detailed error codes and textual descriptions are available from the
Packit 08bd4c
.Fn archive_errno
Packit 08bd4c
and
Packit 08bd4c
.Fn archive_error_string
Packit 08bd4c
functions.
Packit 08bd4c
.\"
Packit 08bd4c
.Sh SEE ALSO
Packit 08bd4c
.Xr tar 1 ,
Packit 08bd4c
.Xr libarchive 3 ,
Packit 08bd4c
.Xr archive_write 3 ,
Packit 08bd4c
.Xr archive_write_blocksize 3 ,
Packit 08bd4c
.Xr archive_write_filter 3 ,
Packit 08bd4c
.Xr archive_write_format 3 ,
Packit 08bd4c
.Xr archive_write_new 3 ,
Packit 08bd4c
.Xr archive_write_set_options 3 ,
Packit 08bd4c
.Xr cpio 5 ,
Packit 08bd4c
.Xr mtree 5 ,
Packit 08bd4c
.Xr tar 5