使用LibTar解压缩文件

当我尝试使用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”。 但我不知道是什么导致了这个错误。

有谁知道发生了什么?

感谢您的关注。

根据man-page,函数声明是:

 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)