Skip to content

Instantly share code, notes, and snippets.

@gregoryfmartin
Created February 24, 2020 16:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gregoryfmartin/4e873781f68ba8500d6a7c8783258303 to your computer and use it in GitHub Desktop.
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