Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
libzip - Open a zip file
#include <stdio.h>
#include <zip.h>
int main () {
printf ("Attempting to open a ZIP file...\n");
int zfile_err = 0;
zip_t* zfile = zip_open ("./testarchive.zip", ZIP_CHECKCONS | ZIP_RDONLY, &zfile_err);
if (NULL == zfile) {
printf ("Failed to open a ZIP file! Error is %i", zfile_err);
return zfile_err;
} else {
printf ("Successfully opened ZIP file!\n");
}
printf ("Closing the ZIP file... \n");
int zfile_closeres = zip_close (zfile);
if (0 > zfile_closeres) {
zip_error_t* close_err = zip_get_error (zfile);
printf ("Error closing the ZIP file! The following error codes were generated: %i, %i\n", close_err->zip_err, close_err->sys_err);
return close_err->zip_err;
}
printf ("Successfully closed the ZIP file!\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.