Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <archive.h>
- #include <archive_entry.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- typedef struct {
- struct archive *archive;
- FILE *stream;
- char buffer[4096];
- } ZipArchive;
- static la_ssize_t
- _read (struct archive *archive, void *data, const void **buffer)
- {
- ZipArchive *zip = (ZipArchive*) data;
- *buffer = zip->buffer;
- return fread (zip->buffer, 1, sizeof (zip->buffer), zip->stream);
- }
- static int
- _close (struct archive *archive, void *data)
- {
- ZipArchive *zip = (ZipArchive*) data;
- fclose (zip->stream);
- return ARCHIVE_OK;
- }
- int
- main (int argc, char *argv[]) {
- struct archive_entry *entry;
- ZipArchive *zip;
- int result;
- zip = malloc (sizeof (ZipArchive));
- zip->archive = archive_read_new ();
- zip->stream = fopen ("archive.zip", "r");
- archive_read_support_format_zip (zip->archive);
- archive_read_open (zip->archive, zip, NULL, _read, _close);
- while (archive_read_next_header (zip->archive, &entry) == ARCHIVE_OK) {
- printf("%s\n", archive_entry_pathname (entry));
- }
- archive_read_free (zip->archive);
- free (zip);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement