]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/archive_write_open.3
MFC r368207,368607:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / archive_write_open.3
1 .\" Copyright (c) 2003-2011 Tim Kientzle
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd November 12, 2020
28 .Dt ARCHIVE_WRITE_OPEN 3
29 .Os
30 .Sh NAME
31 .Nm archive_write_open ,
32 .Nm archive_write_open2 ,
33 .Nm archive_write_open_fd ,
34 .Nm archive_write_open_FILE ,
35 .Nm archive_write_open_filename ,
36 .Nm archive_write_open_memory
37 .Nd functions for creating archives
38 .Sh LIBRARY
39 Streaming Archive Library (libarchive, -larchive)
40 .Sh SYNOPSIS
41 .In archive.h
42 .Ft int
43 .Fo archive_write_open
44 .Fa "struct archive *"
45 .Fa "void *client_data"
46 .Fa "archive_open_callback *"
47 .Fa "archive_write_callback *"
48 .Fa "archive_close_callback *"
49 .Fc
50 .Ft int
51 .Fo archive_write_open2
52 .Fa "struct archive *"
53 .Fa "void *client_data"
54 .Fa "archive_open_callback *"
55 .Fa "archive_write_callback *"
56 .Fa "archive_close_callback *"
57 .Fa "archive_free_callback *"
58 .Fc
59 .Ft int
60 .Fn archive_write_open_fd "struct archive *" "int fd"
61 .Ft int
62 .Fn archive_write_open_FILE "struct archive *" "FILE *file"
63 .Ft int
64 .Fn archive_write_open_filename "struct archive *" "const char *filename"
65 .Ft int
66 .Fo archive_write_open_memory
67 .Fa "struct archive *"
68 .Fa "void *buffer"
69 .Fa "size_t bufferSize"
70 .Fa "size_t *outUsed"
71 .Fc
72 .Sh DESCRIPTION
73 .Bl -tag -width indent
74 .It Fn archive_write_open
75 Freeze the settings, open the archive, and prepare for writing entries.
76 This is the most generic form of this function, which accepts
77 pointers to three callback functions which will be invoked by
78 the compression layer to write the constructed archive.
79 This does not alter the default archive padding.
80 .It Fn archive_write_open2
81 Same as
82 .Fn archive_write_open
83 with an additional fourth free callback. This function should be preferred to
84 .Fn archive_write_open .
85 .It Fn archive_write_open_fd
86 A convenience form of
87 .Fn archive_write_open
88 that accepts a file descriptor.
89 The
90 .Fn archive_write_open_fd
91 function is safe for use with tape drives or other
92 block-oriented devices.
93 .It Fn archive_write_open_FILE
94 A convenience form of
95 .Fn archive_write_open
96 that accepts a
97 .Ft "FILE *"
98 pointer.
99 Note that
100 .Fn archive_write_open_FILE
101 is not safe for writing to tape drives or other devices
102 that require correct blocking.
103 .It Fn archive_write_open_file
104 A deprecated synonym for
105 .Fn archive_write_open_filename .
106 .It Fn archive_write_open_filename
107 A convenience form of
108 .Fn archive_write_open
109 that accepts a filename.
110 A NULL argument indicates that the output should be written to standard output;
111 an argument of
112 .Dq -
113 will open a file with that name.
114 If you have not invoked
115 .Fn archive_write_set_bytes_in_last_block ,
116 then
117 .Fn archive_write_open_filename
118 will adjust the last-block padding depending on the file:
119 it will enable padding when writing to standard output or
120 to a character or block device node, it will disable padding otherwise.
121 You can override this by manually invoking
122 .Fn archive_write_set_bytes_in_last_block
123 before calling
124 .Fn archive_write_open2 .
125 The
126 .Fn archive_write_open_filename
127 function is safe for use with tape drives or other
128 block-oriented devices.
129 .It Fn archive_write_open_memory
130 A convenience form of
131 .Fn archive_write_open2
132 that accepts a pointer to a block of memory that will receive
133 the archive.
134 The final
135 .Ft "size_t *"
136 argument points to a variable that will be updated
137 after each write to reflect how much of the buffer
138 is currently in use.
139 You should be careful to ensure that this variable
140 remains allocated until after the archive is
141 closed.
142 This function will disable padding unless you
143 have specifically set the block size.
144 .El
145 More information about the
146 .Va struct archive
147 object and the overall design of the library can be found in the
148 .Xr libarchive 3
149 overview.
150 .Pp
151 Note that the convenience forms above vary in how
152 they block the output.
153 See
154 .Xr archive_write_blocksize 3
155 if you need to control the block size used for writes
156 or the end-of-file padding behavior.
157 .\"
158 .Sh CLIENT CALLBACKS
159 To use this library, you will need to define and register
160 callback functions that will be invoked to write data to the
161 resulting archive.
162 These functions are registered by calling
163 .Fn archive_write_open2 :
164 .Bl -item -offset indent
165 .It
166 .Ft typedef int
167 .Fn archive_open_callback "struct archive *" "void *client_data"
168 .El
169 .Pp
170 The open callback is invoked by
171 .Fn archive_write_open .
172 It should return
173 .Cm ARCHIVE_OK
174 if the underlying file or data source is successfully
175 opened.
176 If the open fails, it should call
177 .Fn archive_set_error
178 to register an error code and message and return
179 .Cm ARCHIVE_FATAL .
180 Please note that if open fails, close is not called and resources must be
181 freed inside the open callback or with the free callback.
182 .Bl -item -offset indent
183 .It
184 .Ft typedef la_ssize_t
185 .Fo archive_write_callback
186 .Fa "struct archive *"
187 .Fa "void *client_data"
188 .Fa "const void *buffer"
189 .Fa "size_t length"
190 .Fc
191 .El
192 .Pp
193 The write callback is invoked whenever the library
194 needs to write raw bytes to the archive.
195 For correct blocking, each call to the write callback function
196 should translate into a single
197 .Xr write 2
198 system call.
199 This is especially critical when writing archives to tape drives.
200 On success, the write callback should return the
201 number of bytes actually written.
202 On error, the callback should invoke
203 .Fn archive_set_error
204 to register an error code and message and return -1.
205 .Bl -item -offset indent
206 .It
207 .Ft typedef int
208 .Fn archive_close_callback "struct archive *" "void *client_data"
209 .El
210 .Pp
211 The close callback is invoked by archive_close when
212 the archive processing is complete. If the open callback fails, the close
213 callback is not invoked.
214 The callback should return
215 .Cm ARCHIVE_OK
216 on success.
217 On failure, the callback should invoke
218 .Fn archive_set_error
219 to register an error code and message and
220 return
221 .Bl -item -offset indent
222 .It
223 .Ft typedef int
224 .Fn archive_free_callback "struct archive *" "void *client_data"
225 .El
226 .Pp
227 The free callback is always invoked on archive_free.
228 The return code of this callback is not processed.
229 .Pp
230 Note that if the client-provided write callback function
231 returns a non-zero value, that error will be propagated back to the caller
232 through whatever API function resulted in that call, which
233 may include
234 .Fn archive_write_header ,
235 .Fn archive_write_data ,
236 .Fn archive_write_close ,
237 .Fn archive_write_finish ,
238 or
239 .Fn archive_write_free .
240 The client callback can call
241 .Fn archive_set_error
242 to provide values that can then be retrieved by
243 .Fn archive_errno
244 and
245 .Fn archive_error_string .
246 .\" .Sh EXAMPLE
247 .Sh RETURN VALUES
248 These functions return
249 .Cm ARCHIVE_OK
250 on success, or
251 .Cm ARCHIVE_FATAL .
252 .\"
253 .Sh ERRORS
254 Detailed error codes and textual descriptions are available from the
255 .Fn archive_errno
256 and
257 .Fn archive_error_string
258 functions.
259 .\"
260 .Sh SEE ALSO
261 .Xr tar 1 ,
262 .Xr archive_write 3 ,
263 .Xr archive_write_blocksize 3 ,
264 .Xr archive_write_filter 3 ,
265 .Xr archive_write_format 3 ,
266 .Xr archive_write_new 3 ,
267 .Xr archive_write_set_options 3 ,
268 .Xr libarchive 3 ,
269 .Xr cpio 5 ,
270 .Xr mtree 5 ,
271 .Xr tar 5