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