title: Read file contents with unknown size
body: <p>I want to process the contents of a config file.  The config file could be any size.  I am getting a Bus Error, after the program hangs, when I run the following code:</p>
  
  <pre><code>FILE *fp;
  struct stat st;
  char *buffer;
  
  fp = fopen(CONFIG_FILE, "r");
  if (fp == NULL) {
      // error handling and cleanup omitted for brevity
  }
  
  fstat(fileno(fp), &amp;st);
  fread(buffer, sizeof(char), st.st_size, fp);
  fprintf(stderr, "%s\n", *buffer);
  fclose(fp);
  </code></pre>
  
  <p>I have read that a bus error can be caused by a buffer overflow.  I am pretty sure I am getting a buffer overflow with my <code>char *buffer</code>.  But then, <strong>how can I specify the size of the buffer at runtime?</strong></p>
  
  <p><strong>EDIT</strong> - The bus error was caused by my laziness of hardcoding <code>1</code> in the fread call.  The code example has been updated to fix this, using <code>sizeof(char)</code> instead.</p>