我正在尝试使用C语言制作一个tar文件。由于某些原因,我不能使用
system("tar -cvf xxxx.tar xxxx");
我的代码如下:
#include <stdio.h>
#include <libtar.h>
#include <fcntl.h>
int main(void) {
TAR *pTar;
char *tarFilename = "file.tar";
char *srcDir = "directory";
char *extractTo = ".";
tar_open(&pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU);
tar_append_tree(pTar, srcDir, extractTo);
tar_close(pTar);
return (0);
}
运行这段代码后,当我想要使用
untar
命令解压缩时,会发生以下错误:tar -xvf file.tar
我遇到了一个错误。
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
我的C代码有什么问题?