使用在C libtar库 [英] using libtar library in c

查看:558
本文介绍了使用在C libtar库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用c tar文件。对于原因,我无法使用

I am trying to make a tar file using c. For a reason I can not use

系统(焦油-cvf xxxx.tar XXXX);

我的code是:

#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);

}

运行此code,当我想要使用后解压

After running this code, when I want to untar with

tar -xvf file.tar

我得到一个错误

tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

什么是我的C code中的问题?

What is the problem with my c code ?

推荐答案

我认为你需要调用tar_append_eof 的http:// linux.die.net/man/3/tar_append_eof 收盘前tar文件。

I think you need to call tar_append_eof http://linux.die.net/man/3/tar_append_eof before closing the tar file.

该tar_append_eof()函数写入一个EOF标记(所有零中的两个块)与T相关的tar文件。

The tar_append_eof() function writes an EOF marker (two blocks of all zeros) to the tar file associated with t.

这篇关于使用在C libtar库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆