Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 1 | .\" zip_file_add.mdoc -- add files to zip archive |
Thomas Klausner | 86a346b | 2014-08-02 12:10:27 +0200 | [diff] [blame] | 2 | .\" Copyright (C) 2004-2014 Dieter Baron and Thomas Klausner |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 3 | .\" |
| 4 | .\" This file is part of libzip, a library to manipulate ZIP archives. |
| 5 | .\" The authors can be contacted at <libzip@nih.at> |
| 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 | 86a346b | 2014-08-02 12:10:27 +0200 | [diff] [blame] | 32 | .Dd August 2, 2014 |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 33 | .Dt ZIP_FILE_ADD 3 |
| 34 | .Os |
| 35 | .Sh NAME |
| 36 | .Nm zip_file_add , |
| 37 | .Nm zip_file_replace |
| 38 | .Nd add file to zip archive or replace file in zip archive |
| 39 | .Sh LIBRARY |
| 40 | libzip (-lzip) |
| 41 | .Sh SYNOPSIS |
| 42 | .In zip.h |
| 43 | .Ft zip_int64_t |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 44 | .Fn zip_file_add "zip_t *archive" "const char *name" \ |
| 45 | "zip_source_t *source" "zip_flags_t flags" |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 46 | .Ft int |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 47 | .Fn zip_file_replace "zip_t *archive" "zip_uint64_t index" \ |
| 48 | "zip_source_t *source" "zip_flags_t flags" |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 49 | .Sh DESCRIPTION |
| 50 | The function |
| 51 | .Fn zip_file_add |
| 52 | adds a file to a zip archive, while |
| 53 | .Fn zip_file_replace |
| 54 | replaces an existing file in a zip archive. |
| 55 | The argument |
| 56 | .Ar archive |
| 57 | specifies the zip archive to which the file should be added. |
| 58 | .Ar name |
| 59 | is the file's name in the zip archive (for |
| 60 | .Fn zip_file_add ) , |
| 61 | while |
| 62 | .Ar index |
| 63 | specifies which file should be replaced (for |
| 64 | .Fn zip_file_replace ) . |
| 65 | The |
| 66 | .Ar flags |
Thomas Klausner | 8f639be | 2012-06-25 12:15:51 +0200 | [diff] [blame] | 67 | argument can be any combination of |
| 68 | .Dv ZIP_FL_OVERWRITE |
| 69 | with one of |
| 70 | .Dv ZIP_FL_ENC_* : |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 71 | .Bl -tag -width XZIPXFLXENCXSTRICTXX |
| 72 | .It Dv ZIP_FL_OVERWRITE |
| 73 | Overwrite any existing file of the same name. |
| 74 | For |
| 75 | .Nm zip_file_add |
| 76 | only. |
| 77 | .It Dv ZIP_FL_ENC_GUESS |
| 78 | Guess encoding of |
| 79 | .Ar name |
| 80 | (default). |
| 81 | .It Dv ZIP_FL_ENC_UTF_8 |
| 82 | Interpret |
| 83 | .Ar name |
| 84 | as UTF-8. |
| 85 | .It Dv ZIP_FL_ENC_CP437 |
| 86 | Interpret |
| 87 | .Ar name |
| 88 | as code page 437 (CP-437). |
| 89 | .El |
| 90 | The data is obtained from the |
| 91 | .Ar source |
Thomas Klausner | 86a346b | 2014-08-02 12:10:27 +0200 | [diff] [blame] | 92 | argument, see |
| 93 | .Xr zip_source 3 . |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 94 | .Sh RETURN VALUES |
| 95 | Upon successful completion, |
| 96 | .Fn zip_file_add |
| 97 | returns the index of the new file in the archive, and |
| 98 | .Fn zip_file_replace |
| 99 | returns 0. |
| 100 | Otherwise, \-1 is returned and the error code in |
| 101 | .Ar archive |
| 102 | is set to indicate the error. |
| 103 | .Sh EXAMPLES |
| 104 | .Bd -literal -offset indent |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 105 | zip_source_t *s; |
Thomas Klausner | c797b50 | 2012-10-06 22:59:09 +0200 | [diff] [blame] | 106 | const char buf="teststring"; |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 107 | |
Thomas Klausner | c797b50 | 2012-10-06 22:59:09 +0200 | [diff] [blame] | 108 | if ((s=zip_source_buffer(archive, buffer, sizeof(buf), 0)) == NULL || |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 109 | zip_file_add(archive, name, s, ZIP_FL_ENC_UTF_8) \*[Lt] 0) { |
| 110 | zip_source_free(s); |
Thomas Klausner | acf8fd2 | 2012-10-06 22:55:25 +0200 | [diff] [blame] | 111 | printf("error adding file: %s\en", zip_strerror(archive)); |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 112 | } |
| 113 | .Ed |
| 114 | .Sh ERRORS |
| 115 | .Fn zip_file_add |
| 116 | and |
| 117 | .Fn zip_file_replace |
| 118 | fail if: |
| 119 | .Bl -tag -width Er |
| 120 | .It Bq Er ZIP_ER_EXISTS |
| 121 | There is already a file called |
| 122 | .Ar name |
| 123 | in the archive. |
| 124 | (Only applies to |
| 125 | .Fn zip_file_add , |
| 126 | and only if |
| 127 | .Dv ZIP_FL_OVERWRITE |
| 128 | is not provided). |
| 129 | .It Bq Er ZIP_ER_INVAL |
| 130 | .Ar source |
| 131 | or |
| 132 | .Ar name |
| 133 | are |
| 134 | .Dv NULL , |
| 135 | or |
| 136 | .Ar index |
| 137 | is invalid. |
| 138 | .It Bq Er ZIP_ER_MEMORY |
| 139 | Required memory could not be allocated. |
| 140 | .It Bq Er ZIP_ER_RDONLY |
| 141 | Archive was opened in read-only mode. |
| 142 | .El |
| 143 | .Sh SEE ALSO |
| 144 | .Xr libzip 3 , |
Thomas Klausner | 86a346b | 2014-08-02 12:10:27 +0200 | [diff] [blame] | 145 | .Xr zip_source 3 |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 146 | .Sh AUTHORS |
| 147 | .An -nosplit |
Thomas Klausner | 0acbab4 | 2013-07-28 23:29:08 +0200 | [diff] [blame] | 148 | .An Dieter Baron Aq Mt dillo@nih.at |
Thomas Klausner | 354e524 | 2012-06-23 23:27:51 +0200 | [diff] [blame] | 149 | and |
Thomas Klausner | 0acbab4 | 2013-07-28 23:29:08 +0200 | [diff] [blame] | 150 | .An Thomas Klausner Aq Mt tk@giga.or.at |