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 212 213 214 215 216 217 218 219 220 221
|
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_open.mdoc -- open zip archive
.\" Copyright (C) 2003-2022 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <info@libzip.org>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\" 3. The names of the authors may not be used to endorse or promote
.\" products derived from this software without specific prior
.\" written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.TH "ZIP_OPEN" "3" "May 5, 2025" "NiH" "Library Functions Manual"
.nh
.if n .ad l
.SH "NAME"
\fBzip_open\fR,
\fBzip_open_from_source\fR
\- open zip archive
.SH "LIBRARY"
libzip (-lzip)
.SH "SYNOPSIS"
\fB#include <zip.h>\fR
.sp
\fIzip_t *\fR
.br
.PD 0
.HP 4n
\fBzip_open\fR(\fIconst\ char\ *path\fR, \fIint\ flags\fR, \fIint\ *errorp\fR);
.PD
.PP
\fIzip_t *\fR
.br
.PD 0
.HP 4n
\fBzip_open_from_source\fR(\fIzip_source_t\ *zs\fR, \fIint\ flags\fR, \fIzip_error_t\ *ze\fR);
.PD
.SH "DESCRIPTION"
The
\fBzip_open\fR()
function opens the zip archive specified by
\fIpath\fR
and returns a pointer to a
\fIstruct zip\fR,
used to manipulate the archive.
The
\fIflags\fR
are specified by
\fIor\fR'ing
the following values, or 0 for none of them.
.RS 6n
.TP 15n
\fRZIP_CHECKCONS\fR
Perform additional stricter consistency checks on the archive, and
error if they fail.
.TP 15n
\fRZIP_CREATE\fR
Create the archive if it does not exist.
.TP 15n
\fRZIP_EXCL\fR
Error if archive already exists.
.TP 15n
\fRZIP_TRUNCATE\fR
If archive exists, ignore its current contents.
In other words, handle it the same way as an empty archive.
.TP 15n
\fRZIP_RDONLY\fR
Open archive in read-only mode.
.RE
.PP
If an error occurs and
\fIerrorp\fR
is
non-\fRNULL\fR,
it will be set to the corresponding error code.
.PP
The
\fBzip_open_from_source\fR()
function opens a zip archive encapsulated by the zip_source
\fIzs\fR
using the provided
\fIflags\fR.
In case of error, the zip_error
\fIze\fR
is filled in.
.SH "RETURN VALUES"
Upon successful completion
\fBzip_open\fR()
and
\fBzip_open_from_source\fR()
return a
\fIstruct zip\fR
pointer.
Otherwise,
\fRNULL\fR
is returned and
\fBzip_open\fR()
sets
\fI*errorp\fR
to indicate the error, while
\fBzip_open_from\fR(\fIsource\fR)
sets
\fIze\fR
to indicate the error.
.SH "EXAMPLES"
Here's an example of how you could report errors during
\fBzip_open\fR:
.nf
.sp
.RS 0n
zip_t *za;
int err;
if ((za = zip_open(name, 0, &err)) == NULL) {
zip_error_t error;
zip_error_init_with_code(&error, err);
fprintf(stderr, "%s: cannot open zip archive '%s': %s\en",
progname, name, zip_error_strerror(&error));
zip_error_fini(&error);
return -1;
}
.RE
.fi
.SH "ERRORS"
The archive specified by
\fIpath\fR
is opened unless:
.TP 19n
[\fRZIP_ER_EXISTS\fR]
The file specified by
\fIpath\fR
exists and
\fRZIP_EXCL\fR
is set.
.TP 19n
[\fRZIP_ER_INCONS\fR]
Inconsistencies were found in the file specified by
\fIpath\fR.
This error is often caused by specifying
\fRZIP_CHECKCONS\fR
but can also happen without it.
.TP 19n
[\fRZIP_ER_INVAL\fR]
The
\fIpath\fR
argument is
\fRNULL\fR.
.TP 19n
[\fRZIP_ER_MEMORY\fR]
Required memory could not be allocated.
.TP 19n
[\fRZIP_ER_NOENT\fR]
The file specified by
\fIpath\fR
does not exist and
\fRZIP_CREATE\fR
is not set.
.TP 19n
[\fRZIP_ER_NOZIP\fR]
The file specified by
\fIpath\fR
is not a zip archive.
.TP 19n
[\fRZIP_ER_OPEN\fR]
The file specified by
\fIpath\fR
could not be opened.
.TP 19n
[\fRZIP_ER_READ\fR]
A read error occurred; see
\fIerrno\fR
for details.
.TP 19n
[\fRZIP_ER_SEEK\fR]
The file specified by
\fIpath\fR
does not allow seeks.
.PD 0
.PP
For newly created archives,
\fBzip_open\fR()
does not try to create the file; this is done when calling
zip_close(3)
and any errors, like missing write permissions, will
be reported then.
.PD
.SH "SEE ALSO"
libzip(3),
zip_close(3),
zip_error_strerror(3),
zip_fdopen(3),
zip_source(5)
.SH "HISTORY"
\fBzip_open\fR()
and
\fBzip_open_from_source\fR()
were added in libzip 1.0.
.SH "AUTHORS"
Dieter Baron <\fIdillo@nih.at\fR>
and
Thomas Klausner <\fIwiz@gatalith.at\fR>
|