title: Reading a file to string with mmap
body: <p>I'm trying to read a file to a string using mmap.</p>
  
  <p>I was following this example: <a href="http://www.lemoda.net/c/mmap-example/index.html" rel="noreferrer">http://www.lemoda.net/c/mmap-example/index.html</a></p>
  
  <p>My code looks like this</p>
  
  <pre><code>unsigned char *f;
  int size;
  int main(int argc, char const *argv[])
  {
      struct stat s;
      const char * file_name = argv[1];
      int fd = open (argv[1], O_RDONLY);
  
      /* Get the size of the file. */
      int status = fstat (fd, &amp; s);
      size = s.st_size;
  
      f = (char *) mmap (0, size, PROT_READ, 0, fd, 0);
      for (i = 0; i &lt; size; i++) {
          char c;
  
          c = f[i];
          putchar(c);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>But I always receive a segemation fault when accessing f[i].
  What am I doing wrong?</p>