title: mmap() always returns -1
body: <p>I want to map certain sections of a file into the memory and for this purpose I have to use mmap(). (project reqs)
  I open the file with:</p>
  
  <pre><code>file = open(fileName, O_RDWR, 0)
  </code></pre>
  
  <p>and it does open regulary (file != -1).</p>
  
  <p>Then, within a for(), I try to map with:</p>
  
  <pre><code>char *res;
  res = (char*)mmap((void*)sectionHeads[i].adr, sectionHeads[i].size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, file, sectionHeads[i].offset);
  </code></pre>
  
  <p>sectionHead contains adr(int) of the address and so on. But I always get -1 as a result. I checked, and that part of the memory should be free. What am I doing wrong?</p>
  
  <p>note: this is my first time working with mmap(), later on I will think about flags, but right now I just want to map if only one section. Sections contain valid values, double checked that.</p>
  
  <p>update: As suggested I called <code>perror ("mmap error");</code> to see what the error is and I get <code>mmap error: Invalid argument</code>. Values of adr, size and offset of the first sectionHeads are: adr=8154 size=13 offset=154. I've also thrown out MAP_ANON. What argument is invalid? Is there a way to see that?</p>