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
@ -174,6 +174,30 @@ TEST_CASE(TESTPRE "open(w+) truncates file", TESTPAT)
|
||||
REQUIRE( t == "");
|
||||
}
|
||||
|
||||
TEST_CASE(TESTPRE "peek() returns -1 on EOF", TESTPAT)
|
||||
{
|
||||
FS_MOCK_DECLARE(64, 8, 512, "");
|
||||
REQUIRE(FSTYPE.begin());
|
||||
createFile("/file1", "some text");
|
||||
auto f = FSTYPE.open("/file1", "r+");
|
||||
REQUIRE(f.seek(8));
|
||||
REQUIRE(f.peek() == 't');
|
||||
REQUIRE(f.read() == 't');
|
||||
REQUIRE(f.peek() == -1);
|
||||
REQUIRE(f.read() == -1);
|
||||
f.close();
|
||||
}
|
||||
|
||||
TEST_CASE(TESTPRE "seek() pase EOF returns error (#7323)", TESTPAT)
|
||||
{
|
||||
FS_MOCK_DECLARE(64, 8, 512, "");
|
||||
REQUIRE(FSTYPE.begin());
|
||||
createFile("/file1", "some text");
|
||||
auto f = FSTYPE.open("/file1", "r+");
|
||||
REQUIRE_FALSE(f.seek(10));
|
||||
f.close();
|
||||
}
|
||||
|
||||
#ifdef FS_HAS_DIRS
|
||||
|
||||
#if FSTYPE != SDFS
|
||||
|
Reference in New Issue
Block a user