This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: second call to mmap() results in error


On 1/30/2014 2:04 PM, Lavrentiev, Anton (NIH/NLM/NCBI) [C] wrote:
Forget mmap().

Why?  The response was:

Adding the <unistd.h> fixes the problem in all its iterations -- the original mmap()
test works (without the call to ftruncate()), as well as the second one.

Note *the original*.

<http://cygwin.com/ml/cygwin/2014-01/msg00494.html>.  Note here Corinna
says:

  Your testcase is missing an ftruncate or two., btw.

So if the question is why do you need to include ftruncate() in the code, take a look here:

 <http://pubs.opengroup.org/onlinepubs/009695399/functions/mmap.html>.

In particular:

  Note that references beyond the end of the object do not extend the
  object as the new end cannot be determined precisely by most virtual
  memory hardware. Instead, the size can be directly manipulated by
  ftruncate().

So the code as written requires ftruncate() to work in a defined manner.
But if you don't include unistd.h, you don't get the prototype and you
end up with ftruncate() failing, which causes mmap() to fail.

--
Larry

_____________________________________________________________________

A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]