title: Reading whole file into a Buffer
body: <p>I am trying to read a RSA key file into a buffer with the code below</p>
  <pre><code> char* readkeyBuffer(){
      char *buffer;
      long length;
      FILE *f;
      f= fopen (&quot;file.p12&quot;, &quot;rb&quot;);
  
      if (f)
      {
        fseek (f, 0, SEEK_END);
        length = ftell (f);
        rewind(f);
        //fseek (f, 0, SEEK_SET);
        buffer = (char *) malloc (sizeof(char) * (length +1 ));
        
        
        lr_message(&quot;Length = %d&quot;,length);
        lr_message(&quot;sizeof Buffer = %d&quot;,sizeof(buffer));
        
        if (buffer)
        {
          fread (buffer, 1, length, f);
          //strcat(buffer,'\0');
        }
       
        
        lr_message(&quot;sizeof Buffer = %d&quot;,sizeof(buffer));
        lr_message(&quot;buffer len = %d&quot;,strlen(buffer));
        
        //lr_message(&quot;%s&quot;,buffer);
         fclose (f);
      }
      return buffer;
   }
  </code></pre>
  <p>The file size is 4476 , but somehow the file being read into the buffer has only 59 chars. Can you please suggest what is the issue?</p>
  <pre><code>Output ---
  
  Length = 4476
  sizeof Buffer = 4
  sizeof Buffer = 4
  buffer len = 59
  </code></pre>