|
|
|
#include "CFGFileParser.h"
|
|
|
|
#include <climits>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
CFGFileParser::CFGFileParser(const char* filename){
|
|
|
|
// Open the config file, get its size,
|
|
|
|
// allocate the buffer, read it into
|
|
|
|
// the buffer, close the file
|
|
|
|
cfg_file = fopen(filename, "r");
|
|
|
|
stat(filename, cfg_fileinfo);
|
|
|
|
buffer = static_cast<char*>(tlsf_calloc(cfg_fileinfo->st_size & INT_MAX, sizeof(char) & INT_MAX));
|
|
|
|
size_t bytesRead = fread(buffer, sizeof(char) & INT_MAX, cfg_fileinfo->st_size & INT_MAX, cfg_file);
|
|
|
|
fclose(cfg_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFGFileParser::~CFGFileParser(){
|
|
|
|
// clean up!
|
|
|
|
tlsf_free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ntr{
|
|
|
|
size_t string_hash(const fast_string &str){
|
|
|
|
size_t out = 0;
|
|
|
|
// instead of tying this to i386/amd64, because someone is eventually going to
|
|
|
|
// port this to ARM or some RISC nonsense
|
|
|
|
#if UINTPTR_MAX == 0xffffffff
|
|
|
|
MurmurHash3_x86_128 ( &str, sizeof(str), 7904542L, &out );
|
|
|
|
#elif UINTPTR_MAX == 0xffffffffffffffff
|
|
|
|
MurmurHash3_x64_128 ( &str, sizeof(str), 5484754L, &out );
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fast_string_compare(fast_string t1, fast_string t2){
|
|
|
|
int i = strcmp(t1.c_str(), t2.c_str());
|
|
|
|
if (!i){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|