|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "src/exceptions/FileIoException.h"
|
|
|
|
#include "src/exceptions/WrongFileFormatException.h"
|
|
|
@ -59,7 +60,7 @@ char* storm::parser::Parser::trimWhitespaces(char* buf) { |
|
|
|
while ((*buf == ' ') || (*buf == '\t') || (*buf == '\n') || (*buf == '\r')) buf++; |
|
|
|
return buf; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Will stat the given file, open it and map it to memory. |
|
|
|
* If anything of this fails, an appropriate exception is raised |
|
|
@ -86,9 +87,9 @@ storm::parser::MappedFile::MappedFile(const char* filename) { |
|
|
|
LOG4CPLUS_ERROR(logger, "Error in open(" << filename << ")."); |
|
|
|
throw exceptions::FileIoException("storm::parser::MappedFile Error in open()"); |
|
|
|
} |
|
|
|
|
|
|
|
this->data = (char*) mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0); |
|
|
|
if (this->data == (char*)-1) { |
|
|
|
|
|
|
|
this->data = reinterpret_cast<char*>(mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0)); |
|
|
|
if (this->data == reinterpret_cast<char*>(-1)) { |
|
|
|
close(this->file); |
|
|
|
LOG4CPLUS_ERROR(logger, "Error in mmap(" << filename << ")."); |
|
|
|
throw exceptions::FileIoException("storm::parser::MappedFile Error in mmap()"); |
|
|
@ -103,20 +104,20 @@ storm::parser::MappedFile::MappedFile(const char* filename) { |
|
|
|
LOG4CPLUS_ERROR(logger, "Error in _stat(" << filename << ")."); |
|
|
|
throw exceptions::FileIoException("storm::parser::MappedFile Error in stat()"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this->file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|
|
|
if (this->file == INVALID_HANDLE_VALUE) { |
|
|
|
LOG4CPLUS_ERROR(logger, "Error in CreateFileA(" << filename << ")."); |
|
|
|
throw exceptions::FileIoException("storm::parser::MappedFile Error in CreateFileA()"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this->mapping = CreateFileMappingA(this->file, NULL, PAGE_READONLY, (DWORD)(st.st_size >> 32), (DWORD)st.st_size, NULL); |
|
|
|
if (this->mapping == NULL) { |
|
|
|
CloseHandle(this->file); |
|
|
|
LOG4CPLUS_ERROR(logger, "Error in CreateFileMappingA(" << filename << ")."); |
|
|
|
throw exceptions::FileIoException("storm::parser::MappedFile Error in CreateFileMappingA()"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this->data = static_cast<char*>(MapViewOfFile(this->mapping, FILE_MAP_READ, 0, 0, this->st.st_size)); |
|
|
|
if (this->data == NULL) { |
|
|
|
CloseHandle(this->mapping); |
|
|
@ -127,7 +128,7 @@ storm::parser::MappedFile::MappedFile(const char* filename) { |
|
|
|
this->dataend = this->data + this->st.st_size; |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Will unmap the data and close the file. |
|
|
|
*/ |
|
|
|