Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 821695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:40:55+00:00 2026-05-15T02:40:55+00:00

I’m trying to test the sendfile() system call under Linux 2.6.32 to zero-copy data

  • 0

I’m trying to test the sendfile() system call under Linux 2.6.32 to zero-copy data between two regular files.
As far as I understand, it should work: ever since 2.6.22, sendfile() has been implemented using splice(), and both the input file and the output file can be either regular files or sockets.

The following is the content of sendfile_test.c:

#include <sys/sendfile.h>

#include <fcntl.h>
#include <stdio.h>

int main(int argc, char **argv) {
  int result;
  int in_file;
  int out_file;

  in_file = open(argv[1], O_RDONLY);
  out_file = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);

  result = sendfile(out_file, in_file, NULL, 1);
  if (result == -1)
    perror("sendfile");

  close(in_file);
  close(out_file);

  return 0;
}

And when I’m running the following commands:

$ gcc sendfile_test.c 
$ ./a.out infile outfile

The output is

sendfile: Invalid argument

And when running

$ strace ./a.out infile outfile

The output contains

open("infile", O_RDONLY)                = 3
open("outfile", O_WRONLY|O_CREAT|O_TRUNC, 0644) = 4
sendfile(4, 3, NULL, 1)                 = -1 EINVAL (Invalid argument)

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:40:56+00:00Added an answer on May 15, 2026 at 2:40 am

    You forgot to check that argc is equal to 3, i.e. you are opening the output file by the name argv[2] but only give your program one argument (and you are not checking for errors after open(2).)

    You can use strace(1) to find out which system call fails.

    Edit:

    This looks like older kernel to me. Same source (modulo error checking) works fine here under 2.6.33.4 #3 SMP. Also, any particular reason you are copying just one byte?

    #include <sys/sendfile.h>
    #include <err.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    int main( int argc, char *argv[] )
    {
        int in_file, out_file;
    
        if ( argc != 3 )
        {
            fprintf( stderr, "usage: %s <in-file> <out-file>\n", argv[0] );
            exit( 1 );
        }
    
        if (( in_file = open( argv[1], O_RDONLY )) == -1 ) err( 1, "open" );
        if (( out_file = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644 )) == -1 )
            err( 1, "open(2)" );
    
        if ( sendfile( out_file, in_file, NULL, 4096 ) == -1 ) err( 1, "sendfile" );
    
        exit( 0 );
    }
    

    Trace:

    nickf@slack:~/csource/linux/splice$ cc -Wall -pedantic -ggdb -g3 -o sf sndf.c 
    nickf@slack:~/csource/linux/splice$ strace ./sf Makefile mm
    ...
    open("Makefile", O_RDONLY)              = 3
    open("mm", O_WRONLY|O_CREAT|O_TRUNC, 0644) = 4
    sendfile(4, 3, NULL, 4096)              = 239
    exit_group(0)                           = ?
    nickf@slack:~/csource/linux/splice$ diff Makefile mm 
    nickf@slack:~/csource/linux/splice$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.