1ARCHIVE_WRITE_OPEN(3)    BSD Library Functions Manual    ARCHIVE_WRITE_OPEN(3)
2

NAME

4     archive_write_open, archive_write_open_fd, archive_write_open_FILE,
5     archive_write_open_filename, archive_write_open_memory — functions for
6     creating archives
7

LIBRARY

9     Streaming Archive Library (libarchive, -larchive)
10

SYNOPSIS

12     #include <archive.h>
13
14     int
15     archive_write_open(struct archive *, void *client_data,
16         archive_open_callback *, archive_write_callback *,
17         archive_close_callback *);
18
19     int
20     archive_write_open_fd(struct archive *, int fd);
21
22     int
23     archive_write_open_FILE(struct archive *, FILE *file);
24
25     int
26     archive_write_open_filename(struct archive *, const char *filename);
27
28     int
29     archive_write_open_memory(struct archive *, void *buffer,
30         size_t bufferSize, size_t *outUsed);
31

DESCRIPTION

33     archive_write_open()
34             Freeze the settings, open the archive, and prepare for writing
35             entries.  This is the most generic form of this function, which
36             accepts pointers to three callback functions which will be
37             invoked by the compression layer to write the constructed ar‐
38             chive.
39
40     archive_write_open_fd()
41             A convenience form of archive_write_open() that accepts a file
42             descriptor.  The archive_write_open_fd() function is safe for use
43             with tape drives or other block-oriented devices.
44
45     archive_write_open_FILE()
46             A convenience form of archive_write_open() that accepts a FILE *
47             pointer.  Note that archive_write_open_FILE() is not safe for
48             writing to tape drives or other devices that require correct
49             blocking.
50
51     archive_write_open_file()
52             A deprecated synonym for archive_write_open_filename().
53
54     archive_write_open_filename()
55             A convenience form of archive_write_open() that accepts a file‐
56             name.  A NULL argument indicates that the output should be writ‐
57             ten to standard output; an argument of “-” will open a file with
58             that name.  If you have not invoked
59             archive_write_set_bytes_in_last_block(), then
60             archive_write_open_filename() will adjust the last-block padding
61             depending on the file: it will enable padding when writing to
62             standard output or to a character or block device node, it will
63             disable padding otherwise.  You can override this by manually
64             invoking archive_write_set_bytes_in_last_block() before calling
65             archive_write_open().  The archive_write_open_filename() function
66             is safe for use with tape drives or other block-oriented devices.
67
68     archive_write_open_memory()
69             A convenience form of archive_write_open() that accepts a pointer
70             to a block of memory that will receive the archive.  The final
71             size_t * argument points to a variable that will be updated after
72             each write to reflect how much of the buffer is currently in use.
73             You should be careful to ensure that this variable remains allo‐
74             cated until after the archive is closed.
75     More information about the struct archive object and the overall design
76     of the library can be found in the libarchive(3) overview.
77

CLIENT CALLBACKS

79     To use this library, you will need to define and register callback func‐
80     tions that will be invoked to write data to the resulting archive.  These
81     functions are registered by calling archive_write_open():
82
83           typedef int archive_open_callback(struct archive *, void
84           *client_data)
85
86     The open callback is invoked by archive_write_open().  It should return
87     ARCHIVE_OK if the underlying file or data source is successfully opened.
88     If the open fails, it should call archive_set_error() to register an
89     error code and message and return ARCHIVE_FATAL.
90
91           typedef ssize_t archive_write_callback(struct archive *,
92           void *client_data, const void *buffer, size_t length)
93
94     The write callback is invoked whenever the library needs to write raw
95     bytes to the archive.  For correct blocking, each call to the write call‐
96     back function should translate into a single write(2) system call.  This
97     is especially critical when writing archives to tape drives.  On success,
98     the write callback should return the number of bytes actually written.
99     On error, the callback should invoke archive_set_error() to register an
100     error code and message and return -1.
101
102           typedef int archive_close_callback(struct archive *, void
103           *client_data)
104
105     The close callback is invoked by archive_close when the archive process‐
106     ing is complete.  The callback should return ARCHIVE_OK on success.  On
107     failure, the callback should invoke archive_set_error() to register an
108     error code and message and return ARCHIVE_FATAL.
109
110     Note that if the client-provided write callback function returns a non-
111     zero value, that error will be propagated back to the caller through
112     whatever API function resulted in that call, which may include
113     archive_write_header(), archive_write_data(), archive_write_close(),
114     archive_write_finish(), or archive_write_free().  The client callback can
115     call archive_set_error() to provide values that can then be retrieved by
116     archive_errno() and archive_error_string().
117

RETURN VALUES

119     These functions return ARCHIVE_OK on success, or ARCHIVE_FATAL.
120

ERRORS

122     Detailed error codes and textual descriptions are available from the
123     archive_errno() and archive_error_string() functions.
124

SEE ALSO

126     tar(1), libarchive(3), archive_write(3), archive_write_filter(3),
127     archive_write_format(3), archive_write_new(3),
128     archive_write_set_options(3), cpio(5), mtree(5), tar(5)
129
130BSD                            February 2, 2012                            BSD
Impressum