#include "file_reader.h" #define BUFFER_SIZE 16384 File* file_open(const char* filename) { File* retval = malloc(sizeof(File)); retval->name = filename; retval->data = malloc(0); retval->size = 0; FILE* file = fopen(filename, "rb"); if(file) { do { retval->data = realloc(retval->data, retval->size + BUFFER_SIZE); retval->size += fread(&retval->data[retval->size], 1, BUFFER_SIZE, file); } while(!feof(file)); retval->data = realloc(retval->data, retval->size); fclose(file); return retval; } else { perror(filename); return NULL; } } void file_close(File* file) { free(file->data); free(file); } int main() { File* file = file_open("strict.dtd"); puts(file->data); file_close(file); return 0; }