1ARCHIVE_WRITE_OPEN(3) BSD Library Functions Manual ARCHIVE_WRITE_OPEN(3)
2
4 archive_write_open, archive_write_open2, archive_write_open_fd,
5 archive_write_open_FILE, archive_write_open_filename,
6 archive_write_open_memory — functions for 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_open2(struct archive *, void *client_data,
21 archive_open_callback *, archive_write_callback *,
22 archive_close_callback *, archive_free_callback *);
23
24 int
25 archive_write_open_fd(struct archive *, int fd);
26
27 int
28 archive_write_open_FILE(struct archive *, FILE *file);
29
30 int
31 archive_write_open_filename(struct archive *, const char *filename);
32
33 int
34 archive_write_open_memory(struct archive *, void *buffer,
35 size_t bufferSize, size_t *outUsed);
36
38 archive_write_open()
39 Freeze the settings, open the archive, and prepare for writing
40 entries. This is the most generic form of this function, which
41 accepts pointers to three callback functions which will be
42 invoked by the compression layer to write the constructed ar‐
43 chive. This does not alter the default archive padding.
44
45 archive_write_open2()
46 Same as archive_write_open() with an additional fourth free call‐
47 back. This function should be preferred to archive_write_open().
48
49 archive_write_open_fd()
50 A convenience form of archive_write_open() that accepts a file
51 descriptor. The archive_write_open_fd() function is safe for use
52 with tape drives or other block-oriented devices.
53
54 archive_write_open_FILE()
55 A convenience form of archive_write_open() that accepts a FILE *
56 pointer. Note that archive_write_open_FILE() is not safe for
57 writing to tape drives or other devices that require correct
58 blocking.
59
60 archive_write_open_file()
61 A deprecated synonym for archive_write_open_filename().
62
63 archive_write_open_filename()
64 A convenience form of archive_write_open() that accepts a file‐
65 name. A NULL argument indicates that the output should be writ‐
66 ten to standard output; an argument of “-” will open a file with
67 that name. If you have not invoked
68 archive_write_set_bytes_in_last_block(), then
69 archive_write_open_filename() will adjust the last-block padding
70 depending on the file: it will enable padding when writing to
71 standard output or to a character or block device node, it will
72 disable padding otherwise. You can override this by manually
73 invoking archive_write_set_bytes_in_last_block() before calling
74 archive_write_open2(). The archive_write_open_filename() func‐
75 tion is safe for use with tape drives or other block-oriented
76 devices.
77
78 archive_write_open_memory()
79 A convenience form of archive_write_open2() that accepts a
80 pointer to a block of memory that will receive the archive. The
81 final size_t * argument points to a variable that will be updated
82 after each write to reflect how much of the buffer is currently
83 in use. You should be careful to ensure that this variable
84 remains allocated until after the archive is closed. This func‐
85 tion will disable padding unless you have specifically set the
86 block size.
87 More information about the struct archive object and the overall design
88 of the library can be found in the libarchive(3) overview.
89
90 Note that the convenience forms above vary in how they block the output.
91 See archive_write_blocksize(3) if you need to control the block size used
92 for writes or the end-of-file padding behavior.
93
95 To use this library, you will need to define and register callback func‐
96 tions that will be invoked to write data to the resulting archive. These
97 functions are registered by calling archive_write_open2():
98
99 typedef int archive_open_callback(struct archive *, void
100 *client_data)
101
102 The open callback is invoked by archive_write_open(). It should return
103 ARCHIVE_OK if the underlying file or data source is successfully opened.
104 If the open fails, it should call archive_set_error() to register an
105 error code and message and return ARCHIVE_FATAL. Please note that if
106 open fails, close is not called and resources must be freed inside the
107 open callback or with the free callback.
108
109 typedef la_ssize_t archive_write_callback(struct archive *,
110 void *client_data, const void *buffer, size_t length)
111
112 The write callback is invoked whenever the library needs to write raw
113 bytes to the archive. For correct blocking, each call to the write call‐
114 back function should translate into a single write(2) system call. This
115 is especially critical when writing archives to tape drives. On success,
116 the write callback should return the number of bytes actually written.
117 On error, the callback should invoke archive_set_error() to register an
118 error code and message and return -1.
119
120 typedef int archive_close_callback(struct archive *, void
121 *client_data)
122
123 The close callback is invoked by archive_close when the archive process‐
124 ing is complete. If the open callback fails, the close callback is not
125 invoked. The callback should return ARCHIVE_OK on success. On failure,
126 the callback should invoke archive_set_error() to register an error code
127 and message and return
128
129 typedef int archive_free_callback(struct archive *, void
130 *client_data)
131
132 The free callback is always invoked on archive_free. The return code of
133 this callback is not processed.
134
135 Note that if the client-provided write callback function returns a non-
136 zero value, that error will be propagated back to the caller through
137 whatever API function resulted in that call, which may include
138 archive_write_header(), archive_write_data(), archive_write_close(),
139 archive_write_finish(), or archive_write_free(). The client callback can
140 call archive_set_error() to provide values that can then be retrieved by
141 archive_errno() and archive_error_string().
142
144 These functions return ARCHIVE_OK on success, or ARCHIVE_FATAL.
145
147 Detailed error codes and textual descriptions are available from the
148 archive_errno() and archive_error_string() functions.
149
151 tar(1), archive_write(3), archive_write_blocksize(3),
152 archive_write_filter(3), archive_write_format(3), archive_write_new(3),
153 archive_write_set_options(3), libarchive(3), cpio(5), mtree(5), tar(5)
154
155BSD November 12, 2020 BSD