blob: 6e5af20fa9b2a6fda738a77e9a8580c62d7dc5b1 [file] [log] [blame]
Dieter Baron5305cf42006-03-25 16:14:59 +00001.\" $NiH: zip_source_function.mdoc,v 1.15 2006/03/25 11:23:36 wiz Exp $
Thomas Klausner7edc9e22004-11-18 16:48:08 +00002.\"
3.\" zip_source_function.mdoc -- create data source from function
Dieter Baron5305cf42006-03-25 16:14:59 +00004.\" Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner
Thomas Klausner7edc9e22004-11-18 16:48:08 +00005.\"
6.\" This file is part of libzip, a library to manipulate ZIP archives.
7.\" The authors can be contacted at <nih@giga.or.at>
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\" 3. The names of the authors may not be used to endorse or promote
19.\" products derived from this software without specific prior
20.\" written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
23.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
26.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33.\"
Thomas Klausner119086f2006-03-25 11:23:36 +000034.Dd March 25, 2006
Thomas Klausner7edc9e22004-11-18 16:48:08 +000035.Dt ZIP_SOURCE_FUNCTION 3
36.Os
37.Sh NAME
38.Nm zip_source_function
39.Nd create data source from function
40.Sh LIBRARY
41libzip (-lzip)
42.Sh SYNOPSIS
43.In zip.h
Thomas Klausner1bbdbd02005-07-20 17:18:04 +000044.Ft struct zip_source *
Thomas Klausner10687232004-12-22 16:19:54 +000045.Fn zip_source_function "struct zip *archive" "zip_source_callback fn" "void *userdata"
Thomas Klausner7edc9e22004-11-18 16:48:08 +000046.Sh DESCRIPTION
47The function
48.Fn zip_source_function
Dieter Barond0aff312004-12-10 06:13:16 +000049creates a zip source from the user-provided function
50.Ar fn ,
51which must be of the following type:
Thomas Klausner7edc9e22004-11-18 16:48:08 +000052.Bd -literal
Thomas Klausner10687232004-12-22 16:19:54 +000053typedef ssize_t (*zip_source_callback)(void *state,
Thomas Klausnerff0a6512004-12-22 16:21:00 +000054 void *data, size_t len, enum zip_source_cmd cmd);
Thomas Klausner7edc9e22004-11-18 16:48:08 +000055.Ed
56.Pp
Dieter Barond0aff312004-12-10 06:13:16 +000057When called by the library, the first argument is the
Thomas Klausner119086f2006-03-25 11:23:36 +000058.Ar userdata
Dieter Barond0aff312004-12-10 06:13:16 +000059argument supplied to
60.Fn zip_source_function .
61The next two arguments are a buffer
Thomas Klausner7edc9e22004-11-18 16:48:08 +000062.Ar data
63of size
64.Ar len
Dieter Barond0aff312004-12-10 06:13:16 +000065when data is expected to be returned, or else
66.Dv NULL
67and 0.
68The last argument,
69.Ar cmd ,
70specifies which action the function should perform:
Thomas Klausner10687232004-12-22 16:19:54 +000071.Bl -tag -width XZIPXSOURCEXCLOSEXX -offset indent
72.It Dv ZIP_SOURCE_OPEN
Thomas Klausner8d19d682005-06-09 18:54:24 +000073Prepare for reading.
74Return 0 on success, \-1 on error.
Thomas Klausner10687232004-12-22 16:19:54 +000075.It Dv ZIP_SOURCE_READ
Thomas Klausner7edc9e22004-11-18 16:48:08 +000076Read data into the buffer
77.Ar data
78of size
Dieter Barond0aff312004-12-10 06:13:16 +000079.Ar len .
80Return the number of bytes placed into
81.Ar data
82on success, \-1 on error.
Thomas Klausner10687232004-12-22 16:19:54 +000083.It Dv ZIP_SOURCE_CLOSE
Dieter Barond0aff312004-12-10 06:13:16 +000084Reading is done.
Thomas Klausner10687232004-12-22 16:19:54 +000085.It Dv ZIP_SOURCE_STAT
Dieter Baron960c89d2004-12-22 15:35:49 +000086Get meta information for the input data.
Dieter Barond0aff312004-12-10 06:13:16 +000087.Ar data
Thomas Klausner8d19d682005-06-09 18:54:24 +000088points to a struct zip_stat, which should be filled in.
Thomas Klausner119086f2006-03-25 11:23:36 +000089Return sizeof(struct zip_stat) on success, \-1 on error.
Thomas Klausner10687232004-12-22 16:19:54 +000090.It Dv ZIP_SOURCE_ERROR
Thomas Klausner7edc9e22004-11-18 16:48:08 +000091Get error information.
Dieter Barond0aff312004-12-10 06:13:16 +000092.Ar data
93points to an array of two ints, which should be filled with the libzip
94error code and the corresponding system error code for the error that
Thomas Klausner8d19d682005-06-09 18:54:24 +000095occurred.
Thomas Klausner2083f962005-06-09 18:56:15 +000096See
97.Xr zip_errors 3
98for details on the error codes.
Thomas Klausner119086f2006-03-25 11:23:36 +000099Return return(2 * sizeof(int)).
Thomas Klausner10687232004-12-22 16:19:54 +0000100.It Dv ZIP_SOURCE_FREE
Thomas Klausner8d19d682005-06-09 18:54:24 +0000101Clean up and free all resources.
102Return 0.
Thomas Klausner7edc9e22004-11-18 16:48:08 +0000103.El
Dieter Barond0aff312004-12-10 06:13:16 +0000104.Pp
105The library will always issue
Thomas Klausner10687232004-12-22 16:19:54 +0000106.Dv ZIP_SOURCE_OPEN
Dieter Barond0aff312004-12-10 06:13:16 +0000107before issuing
Thomas Klausner10687232004-12-22 16:19:54 +0000108.Dv ZIP_SOURCE_READ .
Dieter Barond0aff312004-12-10 06:13:16 +0000109When it no longer wishes to read from this source, it will issue
Thomas Klausner10687232004-12-22 16:19:54 +0000110.Dv ZIP_SOURCE_CLOSE .
Dieter Barond0aff312004-12-10 06:13:16 +0000111If the library wishes to read the data again, it will issue
Thomas Klausner10687232004-12-22 16:19:54 +0000112.Dv ZIP_SOURCE_OPEN
Thomas Klausner8d19d682005-06-09 18:54:24 +0000113a second time.
114If the function is unable to provide the data again, it should
115return \-1.
Dieter Barond0aff312004-12-10 06:13:16 +0000116.Pp
Thomas Klausner10687232004-12-22 16:19:54 +0000117.Dv ZIP_SOURCE_STAT
Dieter Barond0aff312004-12-10 06:13:16 +0000118can be issued at any time.
Thomas Klausner10687232004-12-22 16:19:54 +0000119.Dv ZIP_SOURCE_ERROR
Dieter Barond0aff312004-12-10 06:13:16 +0000120will only be issued in response to the function
121returning \-1.
Thomas Klausner10687232004-12-22 16:19:54 +0000122.Dv ZIP_SOURCE_FREE
Dieter Barond0aff312004-12-10 06:13:16 +0000123will be the last command issued.
Thomas Klausner7edc9e22004-11-18 16:48:08 +0000124.Sh RETURN VALUES
125Upon successful completion, the created source is returned.
126Otherwise,
127.Dv NULL
128is returned and the error code in
129.Ar archive
130is set to indicate the error.
131.Sh ERRORS
132.Fn zip_source_function
133fails if:
134.Bl -tag -width Er
135.It Bq Er ZIP_ER_MEMORY
136Required memory could not be allocated.
137.El
138.Sh SEE ALSO
Thomas Klausnerbec1cfe2005-06-09 18:50:27 +0000139.Xr libzip 3 ,
Thomas Klausner7edc9e22004-11-18 16:48:08 +0000140.Xr zip_add 3 ,
141.Xr zip_replace 3 ,
Thomas Klausnerfa02d9d2004-11-18 17:26:55 +0000142.Xr zip_source_buffer 3 ,
Thomas Klausner7edc9e22004-11-18 16:48:08 +0000143.Xr zip_source_file 3 ,
144.Xr zip_source_filep 3 ,
145.Xr zip_source_free 3 ,
146.Xr zip_source_zip 3
Thomas Klausnera456cf52005-06-09 21:13:13 +0000147.Sh AUTHORS
148.An -nosplit
149.An Dieter Baron Aq dillo@giga.or.at
Thomas Klausner39b5f9e2005-06-09 21:14:54 +0000150and
Thomas Klausnera456cf52005-06-09 21:13:13 +0000151.An Thomas Klausner Aq tk@giga.or.at