All of lore.kernel.org
 help / color / mirror / Atom feed
From: Reto Glauser <linux@blinkeye.ch>
To: leo mueller <llug.dan@googlemail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: mmap() returns with -EINVAL
Date: Sun, 16 Aug 2009 16:11:19 +0200	[thread overview]
Message-ID: <4A881387.1080701@blinkeye.ch> (raw)
In-Reply-To: <c93f91ee0907300619q2dc38f49q1092b363ed28687@mail.gmail.com>

On 07/30/2009 03:19 PM,  leo mueller wrote:
>
> by doing a mmap() my program exits with -EINVAL and up to now i have
> no clue why... parametes should be right.
>
> do you have any idea?
>

maybe somethings wrong with your socket. mmap-ping a fd for example only works
if you open the fd O_RDWR, e.g.:

   /** Open a file for writing.
    *  - Creating the file if it doesn't exist.
    *  - Truncating it to 0 size if it already exists. (not really needed)
    *
    * Note: "O_WRONLY" mode is not sufficient when mmap-ing.
   **/
   fd = open( FILEPATH, O_RDWR | O_CREAT | O_TRUNC, ( mode_t )0600 );
   if ( fd == -1 )
   {
      perror( "Error opening file for writing" );
      exit( EXIT_FAILURE );
   }

   /**
    * Now the file is ready to be mmap-ped.
   **/
   map = mmap( 0, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
   if ( map == MAP_FAILED )
   {
      close( fd );
      perror( "Error mmapping the file" );
      exit( EXIT_FAILURE );
   }



  reply	other threads:[~2009-08-16 14:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-30 13:19 mmap() returns with -EINVAL leo mueller
2009-08-16 14:11 ` Reto Glauser [this message]
2009-08-16 14:47 ` LDB

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A881387.1080701@blinkeye.ch \
    --to=linux@blinkeye.ch \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=llug.dan@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.