summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/doc/man/archive_write_open.3
blob: 6ae3c22d0fd4563da837b8024a82810a170ce2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
.TH ARCHIVE_WRITE_OPEN 3 "February 2, 2012" ""
.SH NAME
.ad l
\fB\%archive_write_open\fP,
\fB\%archive_write_open_fd\fP,
\fB\%archive_write_open_FILE\fP,
\fB\%archive_write_open_filename\fP,
\fB\%archive_write_open_memory\fP
\- functions for creating archives
.SH LIBRARY
.ad l
Streaming Archive Library (libarchive, -larchive)
.SH SYNOPSIS
.ad l
\fB#include <archive.h>\fP
.br
\fIint\fP
.br
\fB\%archive_write_open\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *client_data\fP, \fI\%archive_open_callback\ *\fP, \fI\%archive_write_callback\ *\fP, \fI\%archive_close_callback\ *\fP);
.br
\fIint\fP
.br
\fB\%archive_write_open_fd\fP(\fI\%struct\ archive\ *\fP, \fI\%int\ fd\fP);
.br
\fIint\fP
.br
\fB\%archive_write_open_FILE\fP(\fI\%struct\ archive\ *\fP, \fI\%FILE\ *file\fP);
.br
\fIint\fP
.br
\fB\%archive_write_open_filename\fP(\fI\%struct\ archive\ *\fP, \fI\%const\ char\ *filename\fP);
.br
\fIint\fP
.br
\fB\%archive_write_open_memory\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *buffer\fP, \fI\%size_t\ bufferSize\fP, \fI\%size_t\ *outUsed\fP);
.SH DESCRIPTION
.ad l
.RS 5
.TP
\fB\%archive_write_open\fP()
Freeze the settings, open the archive, and prepare for writing entries.
This is the most generic form of this function, which accepts
pointers to three callback functions which will be invoked by
the compression layer to write the constructed archive.
.TP
\fB\%archive_write_open_fd\fP()
A convenience form of
\fB\%archive_write_open\fP()
that accepts a file descriptor.
The
\fB\%archive_write_open_fd\fP()
function is safe for use with tape drives or other
block-oriented devices.
.TP
\fB\%archive_write_open_FILE\fP()
A convenience form of
\fB\%archive_write_open\fP()
that accepts a
\fIFILE *\fP
pointer.
Note that
\fB\%archive_write_open_FILE\fP()
is not safe for writing to tape drives or other devices
that require correct blocking.
.TP
\fB\%archive_write_open_file\fP()
A deprecated synonym for
\fB\%archive_write_open_filename\fP().
.TP
\fB\%archive_write_open_filename\fP()
A convenience form of
\fB\%archive_write_open\fP()
that accepts a filename.
A NULL argument indicates that the output should be written to standard output;
an argument of
``-''
will open a file with that name.
If you have not invoked
\fB\%archive_write_set_bytes_in_last_block\fP(),
then
\fB\%archive_write_open_filename\fP()
will adjust the last-block padding depending on the file:
it will enable padding when writing to standard output or
to a character or block device node, it will disable padding otherwise.
You can override this by manually invoking
\fB\%archive_write_set_bytes_in_last_block\fP()
before calling
\fB\%archive_write_open\fP().
The
\fB\%archive_write_open_filename\fP()
function is safe for use with tape drives or other
block-oriented devices.
.TP
\fB\%archive_write_open_memory\fP()
A convenience form of
\fB\%archive_write_open\fP()
that accepts a pointer to a block of memory that will receive
the archive.
The final
\fIsize_t *\fP
argument points to a variable that will be updated
after each write to reflect how much of the buffer
is currently in use.
You should be careful to ensure that this variable
remains allocated until after the archive is
closed.
.RE
More information about the
\fIstruct\fP archive
object and the overall design of the library can be found in the
\fBlibarchive\fP(3)
overview.
.SH CLIENT CALLBACKS
.ad l
To use this library, you will need to define and register
callback functions that will be invoked to write data to the
resulting archive.
These functions are registered by calling
\fB\%archive_write_open\fP():
.RS 5
.IP
\fItypedef int\fP
\fB\%archive_open_callback\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *client_data\fP)
.RE
.PP
The open callback is invoked by
\fB\%archive_write_open\fP().
It should return
\fBARCHIVE_OK\fP
if the underlying file or data source is successfully
opened.
If the open fails, it should call
\fB\%archive_set_error\fP()
to register an error code and message and return
\fBARCHIVE_FATAL\fP.
.RS 5
.IP
\fItypedef la_ssize_t\fP
\fB\%archive_write_callback\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *client_data\fP, \fI\%const\ void\ *buffer\fP, \fI\%size_t\ length\fP)
.RE
.PP
The write callback is invoked whenever the library
needs to write raw bytes to the archive.
For correct blocking, each call to the write callback function
should translate into a single
\fBwrite\fP(2)
system call.
This is especially critical when writing archives to tape drives.
On success, the write callback should return the
number of bytes actually written.
On error, the callback should invoke
\fB\%archive_set_error\fP()
to register an error code and message and return -1.
.RS 5
.IP
\fItypedef int\fP
\fB\%archive_close_callback\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *client_data\fP)
.RE
.PP
The close callback is invoked by archive_close when
the archive processing is complete.
The callback should return
\fBARCHIVE_OK\fP
on success.
On failure, the callback should invoke
\fB\%archive_set_error\fP()
to register an error code and message and
return
\fBARCHIVE_FATAL.\fP
.PP
Note that if the client-provided write callback function
returns a non-zero value, that error will be propagated back to the caller
through whatever API function resulted in that call, which
may include
\fB\%archive_write_header\fP(),
\fB\%archive_write_data\fP(),
\fB\%archive_write_close\fP(),
\fB\%archive_write_finish\fP(),
or
\fB\%archive_write_free\fP().
The client callback can call
\fB\%archive_set_error\fP()
to provide values that can then be retrieved by
\fB\%archive_errno\fP()
and
\fB\%archive_error_string\fP().
.SH RETURN VALUES
.ad l
These functions return
\fBARCHIVE_OK\fP
on success, or
\fBARCHIVE_FATAL\fP.
.SH ERRORS
.ad l
Detailed error codes and textual descriptions are available from the
\fB\%archive_errno\fP()
and
\fB\%archive_error_string\fP()
functions.
.SH SEE ALSO
.ad l
\fBtar\fP(1),
\fBlibarchive\fP(3),
\fBarchive_write\fP(3),
\fBarchive_write_filter\fP(3),
\fBarchive_write_format\fP(3),
\fBarchive_write_new\fP(3),
\fBarchive_write_set_options\fP(3),
\fBcpio\fP(5),
\fBmtree\fP(5),
\fBtar\fP(5)