All pastes #245467 Raw Edit

Unnamed

public text v1 · immutable
#245467 ·published 2006-11-11 00:54 UTC
rendered paste body
  for(i=0;(count = fread(&fbuf[i],1,1024,cfile)) == 1024;i+=1024)
  {
    if ((fbuf = realloc(fbuf,i+1024+1024)) == NULL)
    {
      fprintf(stderr,"Could not allocate memory for config file, barfing.\n");
      exit(EXIT_FAILURE);
    }
  }

  /* If NOT the end-of-file, we must have had an error of some sort, barf and die */
  if (!feof(cfile))
  {
    fprintf(stderr, "An error occurred while reading the config file\n");
    exit(EXIT_FAILURE);
  }

  /* Terminate it with a NULL */
  fbuf[i+count] = '\0';