#include #include #include Filehandler::Filehandler(char *path) { f = NULL; buffer = NULL; this->path = path; } bool Filehandler::open(void) { f = fopen(path, "r"); if (f == NULL) { printf("Unable to open %s\n", path); return false; } return true; } unsigned int Filehandler::size(void) { unsigned int current = ftell(f); fseek(f, 0, SEEK_END); unsigned int s = ftell(f); fseek(f, current, SEEK_SET); return s; } char * Filehandler::read(void) { fseek(f, 0, SEEK_SET); buffer = (char *) calloc(size(), sizeof(char)); int bytesread = fread(buffer, sizeof(char), size(), f); if (bytesread < 0) { return NULL; } return buffer; } void Filehandler::close(void) { fclose(f); free(buffer); }