cfs/src/perfutil/Util.cc
/**
 * Read all bytes in a file and return it as a buffer. The caller is
 * responsible for calling delete[] on the return value.
 *
 * Limitation: This function only handles ASCII files, and does not correctly
 * read files containing NULL characters.
 */
Read all bytes in a file and return it as a buffer. The caller is
responsible for calling delete[] on the return value.

This function only handles ASCII files, and does not correctly
read files containing NULL characters.
Read all bytes in a file and return it as a buffer . The caller is responsible for calling delete [] on the return value . This function only handles ASCII files and does not correctly read files containing NULL characters .
char*
fileGetContents(FILE* f) {
  char* output;
  fseek(f, 0, SEEK_END);
  size_t size = ftell(f) + 1;
  if (size == 0) {
    output = new char[1];
    output[0] = '\0';
  } else {
    output = new char[size];
    output[size - 1] = '\0';
    rewind(f);
    size_t rt = fread(output, sizeof(char), size, f);
    PERFUTIL_UNUSED(rt);
  }
  return output;
}
char * fileGetContents ( FILE * f ) { char * output ; fseek ( f , 0 , SEEK_END ) ; size_t size = ftell ( f ) + 1 ; if ( size == 0 ) { output = new char [ 1 ] ; output [ 0 ] = ' \0 ' ; } else { output = new char [ size ] ; output [ size - 1 ] = ' \0 ' ; rewind ( f ) ; size_t rt = fread ( output , sizeof ( char ) , size , f ) ; PERFUTIL_UNUSED ( rt ) ; } return output ; }
Read all bytes in a file and return it as a buffer.
Read all bytes in a file and return it as a buffer .
// Determine file size // Need an extra byte for the null terminator. // We don't want to allocate memory if the file size is zero, because it is // undefined behavior to dereference such memory.