Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用LibTar提取文件_C++_C_Extract_Tar - Fatal编程技术网

C++ 使用LibTar提取文件

C++ 使用LibTar提取文件,c++,c,extract,tar,C++,C,Extract,Tar,在尝试使用Libtar提取文件时,我遇到了一个小问题 这是我的代码: 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) ==

在尝试使用Libtar提取文件时,我遇到了一个小问题

这是我的代码:

 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;
}
问题是我在tar_extract_all()函数中遇到了错误“Invalid Argument”。但我不知道是什么导致了这个错误

有人知道发生了什么吗


感谢您的关注。

根据手册页,功能声明为:

int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags, int mode, int options);
这意味着您将
O_RDONLY
作为
tartype\u t*type
参数传递。这是不正确的。也许你的意思是:

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

我修复了错误,但仍然不起作用(感谢您的帮助!因此,如果您仍然需要帮助,也许您可以提供更多关于“不工作”的含义的信息。=)仍然存在tar_extract_all()函数中的错误“Invalid Argument”int tar_extract_all()。我看到的其他示例将传递
模式的值。我认为在创建归档文件时会使用此选项,但您可以尝试将其设置为
0644
,而不是当前的
0
。否则,请确保目标目录存在。目标目录存在。我将尝试在模式参数中设置为0644。谢谢你的帮助<代码>修复了错误
-如何修复?