Dieter Baron | 5305cf4 | 2006-03-25 16:14:59 +0000 | [diff] [blame] | 1 | .\" $NiH: zip_source_function.mdoc,v 1.15 2006/03/25 11:23:36 wiz Exp $ |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 2 | .\" |
| 3 | .\" zip_source_function.mdoc -- create data source from function |
Dieter Baron | 5305cf4 | 2006-03-25 16:14:59 +0000 | [diff] [blame] | 4 | .\" Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 5 | .\" |
| 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 Klausner | 119086f | 2006-03-25 11:23:36 +0000 | [diff] [blame] | 34 | .Dd March 25, 2006 |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 35 | .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 |
| 41 | libzip (-lzip) |
| 42 | .Sh SYNOPSIS |
| 43 | .In zip.h |
Thomas Klausner | 1bbdbd0 | 2005-07-20 17:18:04 +0000 | [diff] [blame] | 44 | .Ft struct zip_source * |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 45 | .Fn zip_source_function "struct zip *archive" "zip_source_callback fn" "void *userdata" |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 46 | .Sh DESCRIPTION |
| 47 | The function |
| 48 | .Fn zip_source_function |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 49 | creates a zip source from the user-provided function |
| 50 | .Ar fn , |
| 51 | which must be of the following type: |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 52 | .Bd -literal |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 53 | typedef ssize_t (*zip_source_callback)(void *state, |
Thomas Klausner | ff0a651 | 2004-12-22 16:21:00 +0000 | [diff] [blame] | 54 | void *data, size_t len, enum zip_source_cmd cmd); |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 55 | .Ed |
| 56 | .Pp |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 57 | When called by the library, the first argument is the |
Thomas Klausner | 119086f | 2006-03-25 11:23:36 +0000 | [diff] [blame] | 58 | .Ar userdata |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 59 | argument supplied to |
| 60 | .Fn zip_source_function . |
| 61 | The next two arguments are a buffer |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 62 | .Ar data |
| 63 | of size |
| 64 | .Ar len |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 65 | when data is expected to be returned, or else |
| 66 | .Dv NULL |
| 67 | and 0. |
| 68 | The last argument, |
| 69 | .Ar cmd , |
| 70 | specifies which action the function should perform: |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 71 | .Bl -tag -width XZIPXSOURCEXCLOSEXX -offset indent |
| 72 | .It Dv ZIP_SOURCE_OPEN |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 73 | Prepare for reading. |
| 74 | Return 0 on success, \-1 on error. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 75 | .It Dv ZIP_SOURCE_READ |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 76 | Read data into the buffer |
| 77 | .Ar data |
| 78 | of size |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 79 | .Ar len . |
| 80 | Return the number of bytes placed into |
| 81 | .Ar data |
| 82 | on success, \-1 on error. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 83 | .It Dv ZIP_SOURCE_CLOSE |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 84 | Reading is done. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 85 | .It Dv ZIP_SOURCE_STAT |
Dieter Baron | 960c89d | 2004-12-22 15:35:49 +0000 | [diff] [blame] | 86 | Get meta information for the input data. |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 87 | .Ar data |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 88 | points to a struct zip_stat, which should be filled in. |
Thomas Klausner | 119086f | 2006-03-25 11:23:36 +0000 | [diff] [blame] | 89 | Return sizeof(struct zip_stat) on success, \-1 on error. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 90 | .It Dv ZIP_SOURCE_ERROR |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 91 | Get error information. |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 92 | .Ar data |
| 93 | points to an array of two ints, which should be filled with the libzip |
| 94 | error code and the corresponding system error code for the error that |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 95 | occurred. |
Thomas Klausner | 2083f96 | 2005-06-09 18:56:15 +0000 | [diff] [blame] | 96 | See |
| 97 | .Xr zip_errors 3 |
| 98 | for details on the error codes. |
Thomas Klausner | 119086f | 2006-03-25 11:23:36 +0000 | [diff] [blame] | 99 | Return return(2 * sizeof(int)). |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 100 | .It Dv ZIP_SOURCE_FREE |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 101 | Clean up and free all resources. |
| 102 | Return 0. |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 103 | .El |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 104 | .Pp |
| 105 | The library will always issue |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 106 | .Dv ZIP_SOURCE_OPEN |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 107 | before issuing |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 108 | .Dv ZIP_SOURCE_READ . |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 109 | When it no longer wishes to read from this source, it will issue |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 110 | .Dv ZIP_SOURCE_CLOSE . |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 111 | If the library wishes to read the data again, it will issue |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 112 | .Dv ZIP_SOURCE_OPEN |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 113 | a second time. |
| 114 | If the function is unable to provide the data again, it should |
| 115 | return \-1. |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 116 | .Pp |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 117 | .Dv ZIP_SOURCE_STAT |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 118 | can be issued at any time. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 119 | .Dv ZIP_SOURCE_ERROR |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 120 | will only be issued in response to the function |
| 121 | returning \-1. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 122 | .Dv ZIP_SOURCE_FREE |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 123 | will be the last command issued. |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 124 | .Sh RETURN VALUES |
| 125 | Upon successful completion, the created source is returned. |
| 126 | Otherwise, |
| 127 | .Dv NULL |
| 128 | is returned and the error code in |
| 129 | .Ar archive |
| 130 | is set to indicate the error. |
| 131 | .Sh ERRORS |
| 132 | .Fn zip_source_function |
| 133 | fails if: |
| 134 | .Bl -tag -width Er |
| 135 | .It Bq Er ZIP_ER_MEMORY |
| 136 | Required memory could not be allocated. |
| 137 | .El |
| 138 | .Sh SEE ALSO |
Thomas Klausner | bec1cfe | 2005-06-09 18:50:27 +0000 | [diff] [blame] | 139 | .Xr libzip 3 , |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 140 | .Xr zip_add 3 , |
| 141 | .Xr zip_replace 3 , |
Thomas Klausner | fa02d9d | 2004-11-18 17:26:55 +0000 | [diff] [blame] | 142 | .Xr zip_source_buffer 3 , |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 143 | .Xr zip_source_file 3 , |
| 144 | .Xr zip_source_filep 3 , |
| 145 | .Xr zip_source_free 3 , |
| 146 | .Xr zip_source_zip 3 |
Thomas Klausner | a456cf5 | 2005-06-09 21:13:13 +0000 | [diff] [blame] | 147 | .Sh AUTHORS |
| 148 | .An -nosplit |
| 149 | .An Dieter Baron Aq dillo@giga.or.at |
Thomas Klausner | 39b5f9e | 2005-06-09 21:14:54 +0000 | [diff] [blame] | 150 | and |
Thomas Klausner | a456cf5 | 2005-06-09 21:13:13 +0000 | [diff] [blame] | 151 | .An Thomas Klausner Aq tk@giga.or.at |