libarchive with Xar - can't read contents of 2nd item and above in archive

121 views Asked by At

The following piece of code works fine for formats like TAR, but when i'm using it for XAR, it reads the 1st item successfully, but from the 2nd item and on, the file names and size are retrieved, yet archive_read_data fails (with error code 25 - ENOTTY).

struct archive *a;
struct archive_entry *entry;
a = archive_read_new();
archive_read_support_filter_all(a);
archive_read_support_format_xar(a);

if (archive_read_open_memory(a, data, length) != ARCHIVE_OK)
{
    // Error handling
}

while (archive_read_next_header(a, &entry) == ARCHIVE_OK) 
{
    printf("%s\n",archive_entry_pathname(entry));

    size_t total = archive_entry_size(entry);
    char *buf = malloc(total);

    ssize_t sizeRead = archive_read_data(a, buf, total);
    if (sizeRead < 0) {
        // Error handling
    }
    free(buf);

}

archive_read_free(a);
0

There are 0 answers