Set EOF when reaching the end of the mmap buffer

This commit is contained in:
Erik Hofman 2021-03-16 10:30:27 +01:00
parent e8cbcebad8
commit 84f7faea05
2 changed files with 10 additions and 1 deletions

View File

@ -131,6 +131,10 @@ off_t SGMMapFile::forward(off_t amount) {
amount = size - offset;
}
offset += amount;
if (amount == 0)
eof_flag = true;
return amount;
}
@ -138,8 +142,10 @@ const char* SGMMapFile::advance(off_t amount) {
const char *ptr = buffer + offset;
off_t advanced = forward(amount);
if (advanced != amount)
if (advanced != amount) {
eof_flag = true;
return nullptr;
}
return ptr;
}

View File

@ -115,6 +115,9 @@ public:
// get the pointer to the start of the buffer
inline const char *get() { return buffer; }
// get the pointer to the current offset of the buffer
inline const char *ptr() { return buffer + offset; }
// get the pointer at the current offset and increase the offset by amount
// returns nullptr if the offset pointer would end up beyond the mmap
// buffer size