Set EOF when reaching the end of the mmap buffer
This commit is contained in:
parent
e8cbcebad8
commit
84f7faea05
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user