Extract File With LibTar

我是研究僧i 提交于 2019-12-11 14:57:48

问题


I have a little problem when I'm trying to extract a file using Libtar.

This is my code:

 int htlp_decompress_decompress(char * filename) {

    TAR * tar_file;
    char rootdir[200];
    strcpy(rootdir, "/var/cache/htpackage/");

    if (tar_open(&tar_file, filename, NULL, O_RDONLY, 0, TAR_GNU) == -1) {
        fprintf(stderr, "tar_open(): %s\n", strerror(errno));
        return -1;
    }

    if (tar_extract_all(tar_file, rootdir) != 0) {
        fprintf(stderr, "tar_extract_all(): %s\n", strerror(errno));
        return -1;
    }

    if (tar_close(tar_file) != 0) {
        fprintf(stderr, "tar_close(): %s\n", strerror(errno));
        return -1;
    }

    return 0;
}

The problem is that I'm getting the error "Invalid Argument" in tar_extract_all() function. But I can not know what is causing this error.

Does anyone know what is happening?

Thank you for your attention.


回答1:


According to the man-page, the function declaration is:

int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags, int mode, int options);

That means you're passing O_RDONLY as the tartype_t *type parameter. This is incorrect. Perhaps you meant this:

tar_open(&tar_file, filename, NULL, O_RDONLY, 0, TAR_GNU)


来源:https://stackoverflow.com/questions/17267372/extract-file-with-libtar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!