title: How to add nullterm to end of mmap() output?
body: <p>In general, how would I go about adding a nullterm to the end of a mmap() output, so that I can treat it like a string? Before this gets flagged, I do <em>not</em> want to modify the original file. I'm trying to get the entire file as a string, but the lack of a nullterm <code>\0</code> on the end makes any normal string operations extremely difficult. Since string literals are stored in read-only memory, and there isn't really a way to change the size of that, how would I go about it?</p>
  <pre class="lang-c prettyprint-override"><code>      int fd = fileno(fp);            // convert FILE struct to file descriptor
        char *src = mmap(0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
  </code></pre>
  <p>This is the basis of my program. I'm attempting numerous file operations on it, but doing anything with the last character of the output ends up printing random value from memory, since there's no nullterm.</p>