Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <archive.h>
  2. #include <archive_entry.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stdbool.h>
  6.  
  7. typedef struct {
  8. struct archive *archive;
  9. FILE *stream;
  10. char buffer[4096];
  11. } ZipArchive;
  12.  
  13. static la_ssize_t
  14. _read (struct archive *archive, void *data, const void **buffer)
  15. {
  16. ZipArchive *zip = (ZipArchive*) data;
  17.  
  18. *buffer = zip->buffer;
  19. return fread (zip->buffer, 1, sizeof (zip->buffer), zip->stream);
  20. }
  21.  
  22. static int
  23. _close (struct archive *archive, void *data)
  24. {
  25. ZipArchive *zip = (ZipArchive*) data;
  26.  
  27. fclose (zip->stream);
  28. return ARCHIVE_OK;
  29. }
  30.  
  31. int
  32. main (int argc, char *argv[]) {
  33. struct archive_entry *entry;
  34. ZipArchive *zip;
  35. int result;
  36.  
  37. zip = malloc (sizeof (ZipArchive));
  38. zip->archive = archive_read_new ();
  39. zip->stream = fopen ("archive.zip", "r");
  40. archive_read_support_format_zip (zip->archive);
  41. archive_read_open (zip->archive, zip, NULL, _read, _close);
  42.  
  43. while (archive_read_next_header (zip->archive, &entry) == ARCHIVE_OK) {
  44. printf("%s\n", archive_entry_pathname (entry));
  45. }
  46.  
  47. archive_read_free (zip->archive);
  48. free (zip);
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement