title: Image data is not fetched in entirety when reading an image of unknown size
body: <p>I have an image file that I'm trying to read and store in a buffer <code>buffer</code>.</p>
  <p>However, I'm only picking up the first few characters, and not the entire file.
  I also don't know the total length of the file, so I unfortunately can't tell it to read X number of characters.</p>
  <p>Here is my code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
      char *data;
      read_file(&quot;Dragon.png&quot;, &amp;data);
      printf(&quot;%s&quot;, data);
  }
  
  int read_file(char *file, char **buffer) {
  
      FILE *file_r = fopen(file, &quot;rb&quot;);
      
      if (file_r != NULL) {
      
          fseek(file_r, 0, SEEK_END); // Set file position to end of file
          unsigned long file_size = ftell(file_r); // Record the position (find the total size of the file)
          fseek(file_r, 0, SEEK_SET);  // Move back to the beginning to begin reading
          
          *buffer = malloc(file_size + 1); // Allocate buffer memory
          fread(*buffer, 1, file_size, file_r);
          fclose(file_r);
          
          return file_size; // File read and passed
      }
      return -1; // File not found (or other error)
  }
  </code></pre>
  <p>When running:</p>
  <pre><code>$ gcc read-file.c -oa
  $ ./a
  �PNG
  �
  $ 
  </code></pre>
  <p>I have no idea how to fix this.  How should I proceed?</p>