ZIP_OPEN(3)
β¨ ZIP_OPEN(3) β the "open a zip archive" moment β¨
okay bestie, welcome to section 3 of the manual, ZIP_OPEN(3) π
this is a Library Functions Manual page and it's all about opening zip archives. pull up a chair, we're doing this together π«Ά
πΈ NAME πΈ
zip_open, zip_open_from_source β open zip archive
π LIBRARY π
libzip (-lzip)
like, that's the whole library. she's iconic, she's small, she does everything β¨
π¦ SYNOPSIS π¦
#include <zip.h>
zip_t *
zip_open(const char *path, int flags, int *errorp);
zip_t *
zip_open_from_source(zip_source_t *zs, int flags, zip_error_t *ze);
π DESCRIPTION π
so zip_open() opens the zip archive that path points at and hands you back a pointer to a struct zip β that's your little handle, your main character object, the thing you use to actually manipulate the archive π
the flags? you specify them by or'ing the values below together. or just pass 0 if you want none of them. no thoughts, head empty, defaults only π
ZIP_CHECKCONSβ do extra, stricter consistency checks on the archive, and error out if they fail. she's thorough. she's checking. πZIP_CREATEβ create the archive if it doesn't exist yet. baby's first zip πΌZIP_EXCLβ error if the archive already exists. exclusive behaviour, literally, that's the name πZIP_TRUNCATEβ if the archive exists, ignore whatever's currently in it. in other words: handle it the same way as an empty archive. starting fresh, no baggage πZIP_RDONLYβ open the archive in read-only mode. look but don't touch, bestie π
if an error happens and errorp is non-NULL, it gets set to the corresponding error code. so like, always pass a pointer if you care. and you should care π₯Ί
now zip_open_from_source() β same energy, different entrance. it opens a zip archive that's encapsulated by the zip_source zs, using the flags you provide. and if things go sideways, the zip_error ze gets filled in. no secrets here β¨
π RETURN VALUES π
when it works? zip_open() and zip_open_from_source() both return a struct zip pointer. slay.
when it doesn't? NULL comes back. and then:
zip_open()sets*errorpto indicate the errorzip_open_from(source)setszeto indicate the error
(yes, the original really writes it as zip_open_from(source) β we keep the facts exactly as they are, no editing the lore π)
π EXAMPLES π
here's how you could report errors during zip_open, bestie. take notes π
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\n",
progname, name, zip_error_strerror(&error));
zip_error_fini(&error);
return -1;
}
see how she initialises the error, prints it all pretty, and then cleans up with zip_error_fini? that's self-care. that's hygiene. that's a girl who finishes her routines π§
π ERRORS π
the archive specified by path is opened unless⦠one of these little guys shows up:
[ZIP_ER_EXISTS]β the file specified bypathexists andZIP_EXCLis set. you said exclusive and she said okay then, no π[ZIP_ER_INCONS]β inconsistencies were found in the file specified bypath. this error is often caused by specifyingZIP_CHECKCONS, but it can also happen without it. so like, don't assume it's your fault? but also it might be π[ZIP_ER_INVAL]β thepathargument isNULL. bestie. you gave her nothing.[ZIP_ER_MEMORY]β required memory could not be allocated. the vibes were too big for RAM π[ZIP_ER_NOENT]β the file specified bypathdoes not exist andZIP_CREATEis not set. nothing there, and you didn't ask her to make one π₯Ί[ZIP_ER_NOZIP]β the file specified bypathis not a zip archive. it's givingβ¦ something else entirely π[ZIP_ER_OPEN]β the file specified bypathcould not be opened.[ZIP_ER_READ]β a read error occurred; seeerrnofor details. go checkerrno, she's holding the receipts π[ZIP_ER_SEEK]β the file specified bypathdoes not allow seeks.
β οΈ for newly created archives,zip_open()does not try to create the file. that happens later, when you callzip_close(3). and any errors β like missing write permissions β get reported then. so don't come forzip_open()about it, she literally wasn't involved yet π
π₯ SEE ALSO π₯
libzip(3), zip_close(3), zip_error_strerror(3), zip_fdopen(3), zip_source(5)
go read those too, iykyk π
β HISTORY β
zip_open() and zip_open_from_source() were added in libzip 1.0. vintage. classic. still eating π
π AUTHORS π
Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β legends, honestly, thank you for your service π«Ά
and that's the page, bestie!! this was Debian's build, dated May 5, 2025, from ZIP_OPEN(3) π go forth and open some archives, you absolute icon πβ¨
π¦ where this page comes from
- arch rolling: libzip 1.11.4-1 Β· BSD
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- nixpkgs unstable: libzip 1.11.4
- ubuntu resolute: libzip-dev 1.11.4-2 Β· BSD-3-Clause
- ubuntu stonking: libzip-dev 1.11.4-2build1 Β· BSD-3-Clause
- Copyright (C) 2003-2022 Dieter Baron and Thomas Klausner
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms