#include <textfile.h>

using namespace std;

char* readTextFile(const std::string& fn) {
    // open input stream
    ifstream in(fn.data());
    // check if file exists
    if (!in.is_open())
        ERR("unable to read File: " << fn);

    // find length of file
    in.seekg(0, ios::end);
    long end = in.tellg();
    in.seekg(0);
    long beg = in.tellg();
    long len = end-beg;

    // reserve memory for contents
    char* ret = new char[len+1];
    
    // read character data
    in.read(ret, len);

    // terminate cstring
    ret[len] = '\0';

    LOG("read " << len << " bytes from " << fn);

    return ret;
}

