LibArchive Exception Raised?

M.M Source

I am trying to unzip/untar/ etc... a file located on disk into a memory buffer. However it seems to give an exception ? Does anyone have any idea abou this? Here is my code.... (yes i will add more error checking later...)

struct mydata {
const char* name;
FILE* fd;
void *buff;
};

size_t myread(struct archive *a, void *client_data, const void **buff)
{
struct mydata *mydata = client_data;
*buff = mydata->buff;
return (fread(mydata->buff, 10240, 0, mydata->fd));
}
int myclose(struct archive *a, void *client_data)
{
struct mydata *mydata = client_data;
if (!mydata->fd)
    fclose(mydata->fd);
return (ARCHIVE_OK);
}
void list_archive(const char *name)
{
struct mydata *mydata;
struct archive *a;
struct archive_entry *entry;
mydata = malloc(sizeof(struct mydata));
if (!mydata) {
    printf("Null data!\n");
    return;
}
a = archive_read_new();
mydata->name = name;

mydata->fd = fopen(mydata->name, "rb"); // Include O_BINARY on Windows
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
archive_read_open(a, mydata, 0, myread, myclose);
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {  
    printf("%s\n", archive_entry_pathname(entry));
}
archive_read_finish(a);
free(mydata);
}
int main(unsigned int argc, const char*argv[]) {

list_archive(argv[1]);
    getchar();
return 0;
}
cexceptionlibarchive

Answers

comments powered by Disqus