gpt4 book ai didi

c++ - 使用 LibTar 提取文件

转载 作者:行者123 更新时间:2023-11-30 17:50:27 25 4
gpt4 key购买 nike

当我尝试使用 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() 函数中收到错误“无效参数”。但我不知道是什么导致了这个错误。

有谁知道发生了什么吗?

感谢您的关注。

最佳答案

根据手册页,函数声明是:

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

这意味着您将 O_RDONLY 作为 tartype_t *type 参数传递。这是不正确的。也许你的意思是这样的:

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

关于c++ - 使用 LibTar 提取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com