Created
July 23, 2017 09:42
-
-
Save udaken/1300431729bde0cfa546532b7933ef00 to your computer and use it in GitHub Desktop.
libarchiveでrarを読み取るためのサンプルソース(バージョン3.3.2時点では動作しない)
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
| #ifdef _WIN32 | |
| #include "targetver.h" | |
| #define WIN32_LEAN_AND_MEAN | |
| #define STRICT | |
| #define STRICT_CONST | |
| #include <windows.h> | |
| #else | |
| #include <sys/stat.h> | |
| #include <unistd.h> | |
| typedef long la_ssize_t; | |
| #endif | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <locale.h> | |
| #include <assert.h> | |
| #include "archive.h" | |
| #include "archive_entry.h" | |
| int main() | |
| { | |
| setlocale(LC_CTYPE, ""); | |
| int r; | |
| struct archive *a = archive_read_new(); | |
| FILE *fp = fopen("aa.rar", "rb"); | |
| assert(a != NULL); | |
| assert(fp != NULL); | |
| archive_read_support_filter_all(a); | |
| archive_read_support_format_rar(a); | |
| r = archive_read_open_FILE(a, fp); | |
| assert(r == ARCHIVE_OK); | |
| do | |
| { | |
| struct archive_entry *ae = NULL; | |
| r = archive_read_next_header(a, &ae); | |
| if (r == ARCHIVE_EOF) | |
| break; | |
| assert(r == ARCHIVE_OK); | |
| printf("%s\t%s 0x%04X\n", archive_entry_pathname(ae), archive_entry_strmode(ae), archive_entry_filetype(ae)); | |
| size_t buffsize = archive_entry_size(ae); | |
| void *buff = malloc(buffsize); | |
| assert(buff != NULL); | |
| for (;;) { | |
| la_ssize_t size; | |
| size = archive_read_data(a, buff, buffsize); | |
| assert(size >= 0); | |
| if (size == 0) | |
| break; | |
| //write(1, buff, size); | |
| } | |
| } while (1); | |
| archive_read_free(a); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment