1ARCHIVE_WRITE_OPEN(3) BSD Library Functions Manual ARCHIVE_WRITE_OPEN(3)
2
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
9 Streaming Archive Library (libarchive, -larchive)
10
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
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. This does not alter the default archive padding.
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. This function will dis‐
75 able padding unless you have specifically set the block size.
76 More information about the struct archive object and the overall design
77 of the library can be found in the libarchive(3) overview.
78
79 Note that the convenience forms above vary in how they block the output.
80 See archive_write_blocksize(3) if you need to control the block size used
81 for writes or the end-of-file padding behavior.
82
84 To use this library, you will need to define and register callback func‐
85 tions that will be invoked to write data to the resulting archive. These
86 functions are registered by calling archive_write_open():
87
88 typedef int archive_open_callback(struct archive *, void
89 *client_data)
90
91 The open callback is invoked by archive_write_open(). It should return
92 ARCHIVE_OK if the underlying file or data source is successfully opened.
93 If the open fails, it should call archive_set_error() to register an
94 error code and message and return ARCHIVE_FATAL.
95
96 typedef la_ssize_t archive_write_callback(struct archive *,
97 void *client_data, const void *buffer, size_t length)
98
99 The write callback is invoked whenever the library needs to write raw
100 bytes to the archive. For correct blocking, each call to the write call‐
101 back function should translate into a single write(2) system call. This
102 is especially critical when writing archives to tape drives. On success,
103 the write callback should return the number of bytes actually written.
104 On error, the callback should invoke archive_set_error() to register an
105 error code and message and return -1.
106
107 typedef int archive_close_callback(struct archive *, void
108 *client_data)
109
110 The close callback is invoked by archive_close when the archive process‐
111 ing is complete. The callback should return ARCHIVE_OK on success. On
112 failure, the callback should invoke archive_set_error() to register an
113 error code and message and return ARCHIVE_FATAL.
114
115 Note that if the client-provided write callback function returns a non-
116 zero value, that error will be propagated back to the caller through
117 whatever API function resulted in that call, which may include
118 archive_write_header(), archive_write_data(), archive_write_close(),
119 archive_write_finish(), or archive_write_free(). The client callback can
120 call archive_set_error() to provide values that can then be retrieved by
121 archive_errno() and archive_error_string().
122
124 These functions return ARCHIVE_OK on success, or ARCHIVE_FATAL.
125
127 Detailed error codes and textual descriptions are available from the
128 archive_errno() and archive_error_string() functions.
129
131 tar(1), archive_write(3), archive_write_blocksize(3),
132 archive_write_filter(3), archive_write_format(3), archive_write_new(3),
133 archive_write_set_options(3), libarchive(3), cpio(5), mtree(5), tar(5)
134
135BSD February 2, 2012 BSD