mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Return FALSE on seek past EOF (#7324)
Fixes #7323 While I'm not a fan, the Arduino FileSeek API online shows that a seek() past EOF should return FALSE. https://www.arduino.cc/en/Reference/FileSeek SPIFFS and SDFS obey this, but LittleFS followed the POSIX standard or allowing seeks past EOF. Update LittleFS::seek() to follow the Arduino API and add tests for it.
This commit is contained in:
committed by
GitHub
parent
27ef03fc05
commit
8ee67ab2b5
@ -377,11 +377,16 @@ public:
|
||||
if (mode == SeekEnd) {
|
||||
offset = -offset; // TODO - this seems like its plain wrong vs. POSIX
|
||||
}
|
||||
auto lastPos = position();
|
||||
int rc = lfs_file_seek(_fs->getFS(), _getFD(), offset, (int)mode); // NB. SeekMode === LFS_SEEK_TYPES
|
||||
if (rc < 0) {
|
||||
DEBUGV("lfs_file_seek rc=%d\n", rc);
|
||||
return false;
|
||||
}
|
||||
if (position() > size()) {
|
||||
seek(lastPos, SeekSet); // Pretend the seek() never happened
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user