libtar 使用范例

本文介绍了如何使用libtar库来操作tar文件,包括读取、截断和追加文件。通过提供的C++代码示例,详细解释了tarAppendFile函数的工作流程,帮助理解libtar的API用法。
摘要由CSDN通过智能技术生成

首先要下载安装一下libtar,网上很容易找到,安装之后读读libtar.h这个文件。熟悉一下具体的function,function的说明

http://linux.die.net/man/3/tar_extract_all

下面是一个测试例子,看看就知道怎么用了。

      1 #include <tar.h>
      2 #include <libtar.h>
      3 #include <iostream>                                                           
      4 #include <fcntl.h>  
      5 using namespace std;                             
      6                                 
-     7 int main(){                                                      
|     8     // tar                       
|-    9     if(0){                                                        
||   10         TAR* tar_handle;                                                                                          
||   11         char* tar_fname = "test.tar";                                                     
||   12         tar_open(&tar_handle, tar_fname, NULL,  O_WRONLY | O_CREAT,  0644,  TAR_GNU);                             
||   13         char* subfile1 = "1.txt";                                                                                 
||   14         tar_append_file(tar_handle, subfile1,  subfile1);                                                         
||   15         char* subfile2 = "2.txt";                                                                                 
||   16         tar_append_file(tar_handle, subfile2,  subfile2);                                                         
|
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值