我正在尝试使用c创建一个tar文件.我无法使用的原因
system(“tar -cvf xxxx.tar xxxx”);
我的代码是:
#include
#include
#include
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);
}
运行此代码后,当我想解压缩时
tar -xvf file.tar
我收到了一个错误
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
我的c代码有什么问题?