1ZIP_OPEN(3)              BSD Library Functions Manual              ZIP_OPEN(3)
2

NAME

4     zip_open, zip_open_from_source — open zip archive
5

LIBRARY

7     libzip (-lzip)
8

SYNOPSIS

10     #include <zip.h>
11
12     zip_t *
13     zip_open(const char *path, int flags, int *errorp);
14
15     zip_t *
16     zip_open_from_source(zip_source_t *zs, int flags, zip_error_t *ze);
17

DESCRIPTION

19     The zip_open() function opens the zip archive specified by path and re‐
20     turns a pointer to a struct zip, used to manipulate the archive.  The
21     flags are specified by or'ing the following values, or 0 for none of
22     them.
23
24           ZIP_CHECKCONS  Perform additional stricter consistency checks on
25                          the archive, and error if they fail.
26
27           ZIP_CREATE     Create the archive if it does not exist.
28
29           ZIP_EXCL       Error if archive already exists.
30
31           ZIP_TRUNCATE   If archive exists, ignore its current contents.  In
32                          other words, handle it the same way as an empty ar‐
33                          chive.
34
35           ZIP_RDONLY     Open archive in read-only mode.
36
37     If an error occurs and errorp is non-NULL, it will be set to the corre‐
38     sponding error code.
39
40     The zip_open_from_source() function opens a zip archive encapsulated by
41     the zip_source zs using the provided flags.  In case of error, the
42     zip_error ze is filled in.
43

RETURN VALUES

45     Upon successful completion zip_open() and zip_open_from_source() return a
46     struct zip pointer.  Otherwise, NULL is returned and zip_open() sets
47     *errorp to indicate the error, while zip_open_from(source) sets ze to in‐
48     dicate the error.
49

EXAMPLES

51     Here's an example of how you could report errors during zip_open:
52
53         zip_t *za;
54         int err;
55
56         if ((za = zip_open(name, 0, &err)) == NULL) {
57             zip_error_t error;
58             zip_error_init_with_code(&error, err);
59             fprintf(stderr, "%s: cannot open zip archive '%s': %s\n",
60                     progname, name, zip_error_strerror(&error));
61             zip_error_fini(&error);
62             return -1;
63         }
64

ERRORS

66     The archive specified by path is opened unless:
67
68     [ZIP_ER_EXISTS]    The file specified by path exists and ZIP_EXCL is set.
69
70     [ZIP_ER_INCONS]    Inconsistencies were found in the file specified by
71                        path.  This error is often caused by specifying
72                        ZIP_CHECKCONS but can also happen without it.
73
74     [ZIP_ER_INVAL]     The path argument is NULL.
75
76     [ZIP_ER_MEMORY]    Required memory could not be allocated.
77
78     [ZIP_ER_NOENT]     The file specified by path does not exist and
79                        ZIP_CREATE is not set.
80
81     [ZIP_ER_NOZIP]     The file specified by path is not a zip archive.
82
83     [ZIP_ER_OPEN]      The file specified by path could not be opened.
84
85     [ZIP_ER_READ]      A read error occurred; see errno for details.
86
87     [ZIP_ER_SEEK]      The file specified by path does not allow seeks.
88     For newly created archives, zip_open() does not try to create the file;
89     this is done when calling zip_close(3) and any errors, like missing write
90     permissions, will be reported then.
91

SEE ALSO

93     libzip(3), zip_close(3), zip_error_strerror(3), zip_fdopen(3)
94

HISTORY

96     zip_open() and zip_open_from_source() were added in libzip 1.0.
97

AUTHORS

99     Dieter Baron <dillo@nih.at> and Thomas Klausner <tk@giga.or.at>
100
101BSD                             October 9, 2022                            BSD
Impressum