Invalid argument when calling linux splice ()

I wanted to try a splice screenshot. I have this function - it should copy the contents of one file to another:

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], NULL, BUFSIZE, SPLICE_F_MORE | SPLICE_F_MOVE ) ) < 0 ) {
                        perror( "splice" );
                        exit( EXIT_FAILURE );
                }

                if ( splice( filedes[0], NULL, out, NULL, rcvd, SPLICE_F_MORE | SPLICE_F_MOVE ) < 0 ) {
                        perror( "splice" );
                        exit( EXIT_FAILURE );
                }
        }
}

The second splice call in the first iteration returns EINVAL each time (invalid argument from perror) - what could be the reason?

+5
source share
2 answers

From 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.
       ...    

An OP comment indicates that he opened the file in append mode.

+1
source

I have no idea this is the best way to do this, but this works for me:

http://vectrex.org.uk/mark/splicecopy.cpp

. . , splice(), 64k .

Fedora 13 x86_64 , , (ish) .

-1

All Articles