相关疑难解决方法(0)

在c中使用libtar库

我正在尝试使用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);

}
Run Code Online (Sandbox Code Playgroud)

运行此代码后,当我想解压缩时

tar -xvf file.tar
Run Code Online (Sandbox Code Playgroud)

我收到了一个错误

tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
Run Code Online (Sandbox Code Playgroud)

我的c代码有什么问题?

c linux tar

7
推荐指数
1
解决办法
5384
查看次数

标签 统计

c ×1

linux ×1

tar ×1