Created
June 16, 2013 13:13
-
-
Save khajavi/5792009 to your computer and use it in GitHub Desktop.
Example of reading elements of archive file by using libarchive library.
This file contains hidden or 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 <archive.h> | |
#include <archive_entry.h> | |
int main() { | |
struct archive* a; | |
struct archive_entry* entry; | |
int r; | |
a = archive_read_new(); | |
archive_read_support_filter_all( a ); | |
archive_read_support_format_all( a ); | |
r = archive_read_open_filename( a, "archive.tar.bz2", 10240 ); | |
if( r != ARCHIVE_OK ) | |
exit( 1 ); | |
while( archive_read_next_header( a, &entry ) == ARCHIVE_OK ) { | |
printf("%s\n", archive_entry_pathname( entry ) ); | |
archive_read_data_skip( a ); // Optional | |
} | |
r = archive_read_free( a ); | |
if( r != ARCHIVE_OK ) | |
exit( 1 ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment