调用linux splice()时参数无效
发布时间:2020-12-14 01:39:19  所属栏目:Linux  来源:网络整理 
            导读:我想尝试拼接系统调用.我有这个功能 – 它应该将一个文件的内容复制到另一个文件: static void test_splice( int in,int out ) { int i = 0,rcvd = 0; int filedes[2]; off_t off = 0; if ( pipe( filedes ) 0 ) { perror( "Kicha pipe" ); exit( EXIT_FAIL
                
                
                
            | 
                         
 我想尝试拼接系统调用.我有这个功能 – 它应该将一个文件的内容复制到另一个文件: 
  
  
  
static void test_splice( int in,int out ) {
        int i = 0,rcvd = 0;
        int filedes[2];
        off_t off = 0;
        if ( pipe( filedes ) < 0 ) {
                perror( "Kicha pipe" );
                exit( EXIT_FAILURE );
        }
        for ( i = 0; i < NUMLOOPS; ++i ) {
                if ( ( rcvd = splice( in,NULL,filedes[1],BUFSIZE,SPLICE_F_MORE | SPLICE_F_MOVE ) ) < 0 ) {
                        perror( "splice" );
                        exit( EXIT_FAILURE );
                }
                if ( splice( filedes[0],out,rcvd,SPLICE_F_MORE | SPLICE_F_MOVE ) < 0 ) {
                        perror( "splice" );
                        exit( EXIT_FAILURE );
                }
        }
} 
 第一次迭代中对splice的第二次调用每次返回EINVAL(来自perror的无效参数) – 可能是什么原因? 解决方法
 从 
  
        splice(2)开始: 
  
  
 ERRORS
       ...    
       EINVAL Target  filesystem  doesn't  support  splicing;  target  file is
              opened in append mode; neither of the file descriptors refers to
              a pipe; or offset given for nonseekable device.
       ... 
 OP的评论表明他以附加模式打开了文件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
