Created
February 24, 2020 16:03
Star
You must be signed in to star a gist
libzip - Open a zip file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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