Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 1 | .\" zip_source_function.mdoc \-- create data source from function |
Thomas Klausner | 83ac954 | 2006-04-09 14:52:44 +0000 | [diff] [blame] | 2 | .\" Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 3 | .\" |
| 4 | .\" This file is part of libzip, a library to manipulate ZIP archives. |
Dieter Baron | b86c433 | 2007-11-07 14:35:13 +0100 | [diff] [blame] | 5 | .\" The authors can be contacted at <libzip@nih.at> |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 6 | .\" |
| 7 | .\" Redistribution and use in source and binary forms, with or without |
| 8 | .\" modification, are permitted provided that the following conditions |
| 9 | .\" are met: |
| 10 | .\" 1. Redistributions of source code must retain the above copyright |
| 11 | .\" notice, this list of conditions and the following disclaimer. |
| 12 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 13 | .\" notice, this list of conditions and the following disclaimer in |
| 14 | .\" the documentation and/or other materials provided with the |
| 15 | .\" distribution. |
| 16 | .\" 3. The names of the authors may not be used to endorse or promote |
| 17 | .\" products derived from this software without specific prior |
| 18 | .\" written permission. |
| 19 | .\" |
| 20 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS |
| 21 | .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY |
| 24 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 26 | .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 28 | .\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 29 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 30 | .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | .\" |
Thomas Klausner | 59fc32f | 2007-03-04 11:14:14 +0000 | [diff] [blame] | 32 | .TH ZIP_SOURCE_FUNCTION 3 "March 4, 2007" NiH |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 33 | .SH "NAME" |
| 34 | zip_source_function \- create data source from function |
| 35 | .SH "LIBRARY" |
| 36 | libzip (-lzip) |
| 37 | .SH "SYNOPSIS" |
Thomas Klausner | f4ac13a | 2006-10-03 18:58:00 +0000 | [diff] [blame] | 38 | #include <zip.h> |
| 39 | .PP |
| 40 | struct zip_source * |
| 41 | zip_source_function(struct zip *archive, zip_source_callback fn, void *userdata); |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 42 | .SH "DESCRIPTION" |
| 43 | The function |
Thomas Klausner | f4ac13a | 2006-10-03 18:58:00 +0000 | [diff] [blame] | 44 | zip_source_function |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 45 | creates a zip source from the user-provided function |
| 46 | \fBfn,\fR |
| 47 | which must be of the following type: |
| 48 | .Bd \-literal |
| 49 | typedef ssize_t (*zip_source_callback)(void *state, |
| 50 | void *data, size_t len, enum zip_source_cmd cmd); |
| 51 | .Ed |
| 52 | .PP |
| 53 | When called by the library, the first argument is the |
Thomas Klausner | 83ac954 | 2006-04-09 14:52:44 +0000 | [diff] [blame] | 54 | \fBuserdata\fR |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 55 | argument supplied to |
Thomas Klausner | f4ac13a | 2006-10-03 18:58:00 +0000 | [diff] [blame] | 56 | zip_source_function. |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 57 | The next two arguments are a buffer |
| 58 | \fBdata\fR |
| 59 | of size |
| 60 | \fBlen\fR |
| 61 | when data is expected to be returned, or else |
| 62 | \fBNULL\fR |
| 63 | and 0. |
| 64 | The last argument, |
| 65 | \fBcmd,\fR |
| 66 | specifies which action the function should perform: |
| 67 | .RS |
| 68 | .TP 21 |
| 69 | \fBZIP_SOURCE_OPEN\fR |
Thomas Klausner | 3dd81d8 | 2005-06-09 19:01:53 +0000 | [diff] [blame] | 70 | Prepare for reading. |
| 71 | Return 0 on success, \-1 on error. |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 72 | .TP 21 |
| 73 | \fBZIP_SOURCE_READ\fR |
| 74 | Read data into the buffer |
| 75 | \fBdata\fR |
| 76 | of size |
| 77 | \fBlen.\fR |
| 78 | Return the number of bytes placed into |
| 79 | \fBdata\fR |
| 80 | on success, \-1 on error. |
| 81 | .TP 21 |
| 82 | \fBZIP_SOURCE_CLOSE\fR |
| 83 | Reading is done. |
| 84 | .TP 21 |
| 85 | \fBZIP_SOURCE_STAT\fR |
| 86 | Get meta information for the input data. |
| 87 | \fBdata\fR |
Thomas Klausner | 3dd81d8 | 2005-06-09 19:01:53 +0000 | [diff] [blame] | 88 | points to a struct zip_stat, which should be filled in. |
Thomas Klausner | ead13a7 | 2006-12-29 20:36:49 +0000 | [diff] [blame] | 89 | (See |
| 90 | zip_stat_init(3). ) |
Thomas Klausner | 59fc32f | 2007-03-04 11:14:14 +0000 | [diff] [blame] | 91 | Usually, for uncompressed data, after |
| 92 | zip_stat_init(3), |
| 93 | only the mtime and size struct members will need to be set. |
Thomas Klausner | 83ac954 | 2006-04-09 14:52:44 +0000 | [diff] [blame] | 94 | Return sizeof(struct zip_stat) on success, \-1 on error. |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 95 | .TP 21 |
| 96 | \fBZIP_SOURCE_ERROR\fR |
| 97 | Get error information. |
| 98 | \fBdata\fR |
| 99 | points to an array of two ints, which should be filled with the libzip |
| 100 | error code and the corresponding system error code for the error that |
Thomas Klausner | 3dd81d8 | 2005-06-09 19:01:53 +0000 | [diff] [blame] | 101 | occurred. |
| 102 | See |
| 103 | zip_errors(3) |
| 104 | for details on the error codes. |
Thomas Klausner | 83ac954 | 2006-04-09 14:52:44 +0000 | [diff] [blame] | 105 | Return return(2 * sizeof(int)). |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 106 | .TP 21 |
| 107 | \fBZIP_SOURCE_FREE\fR |
Thomas Klausner | 3dd81d8 | 2005-06-09 19:01:53 +0000 | [diff] [blame] | 108 | Clean up and free all resources. |
| 109 | Return 0. |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 110 | .RE |
| 111 | .PP |
| 112 | The library will always issue |
| 113 | \fBZIP_SOURCE_OPEN\fR |
| 114 | before issuing |
| 115 | \fBZIP_SOURCE_READ.\fR |
| 116 | When it no longer wishes to read from this source, it will issue |
| 117 | \fBZIP_SOURCE_CLOSE.\fR |
| 118 | If the library wishes to read the data again, it will issue |
| 119 | \fBZIP_SOURCE_OPEN\fR |
Thomas Klausner | 3dd81d8 | 2005-06-09 19:01:53 +0000 | [diff] [blame] | 120 | a second time. |
| 121 | If the function is unable to provide the data again, it should |
| 122 | return \-1. |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 123 | .PP |
| 124 | \fBZIP_SOURCE_STAT\fR |
| 125 | can be issued at any time. |
| 126 | \fBZIP_SOURCE_ERROR\fR |
| 127 | will only be issued in response to the function |
| 128 | returning \-1. |
| 129 | \fBZIP_SOURCE_FREE\fR |
| 130 | will be the last command issued. |
| 131 | .SH "RETURN VALUES" |
| 132 | Upon successful completion, the created source is returned. |
| 133 | Otherwise, |
| 134 | \fBNULL\fR |
| 135 | is returned and the error code in |
| 136 | \fBarchive\fR |
| 137 | is set to indicate the error. |
| 138 | .SH "ERRORS" |
Thomas Klausner | f4ac13a | 2006-10-03 18:58:00 +0000 | [diff] [blame] | 139 | zip_source_function |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 140 | fails if: |
| 141 | .RS |
| 142 | .TP 4 |
Thomas Klausner | f4ac13a | 2006-10-03 18:58:00 +0000 | [diff] [blame] | 143 | [ZIP_ER_MEMORY] |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 144 | Required memory could not be allocated. |
| 145 | .RE |
| 146 | .SH "SEE ALSO" |
Thomas Klausner | 3dd81d8 | 2005-06-09 19:01:53 +0000 | [diff] [blame] | 147 | libzip(3), |
Thomas Klausner | 41f7750 | 2005-05-20 22:01:09 +0000 | [diff] [blame] | 148 | zip_add(3), |
| 149 | zip_replace(3), |
| 150 | zip_source_buffer(3), |
| 151 | zip_source_file(3), |
| 152 | zip_source_filep(3), |
| 153 | zip_source_free(3), |
Thomas Klausner | ead13a7 | 2006-12-29 20:36:49 +0000 | [diff] [blame] | 154 | zip_source_zip(3), |
| 155 | zip_stat_init(3) |
Thomas Klausner | 7533013 | 2005-06-17 12:59:06 +0000 | [diff] [blame] | 156 | .SH "AUTHORS" |
| 157 | |
| 158 | Dieter Baron <dillo@giga.or.at> |
| 159 | and |
| 160 | Thomas Klausner <tk@giga.or.at> |