[C.C++] c语言 调用lib,在c中使用libtar库

729 0
Honkers 2025-3-27 06:37:36 来自手机 | 显示全部楼层 |阅读模式

我正在尝试使用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代码有什么问题?

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Honkers

荣誉红客

关注
  • 4010
    主题
  • 36
    粉丝
  • 0
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行