1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Reimplement SD.h write methods exactly in File (#5861)

* Reimplement SD.h write methods exactly in File

Replace the individual override with the existing SD.h File's
implementation for all methods of File::write.

Fixes #5846

* Add add'l tests

* Fix Print and File incompatible writes w/casts

Print and File have ambiguous resolutions for single-argument
write(0)s.

Fix by adding explicit methods.  A write of any integer will not be a
const char* write (i.e. won't write a string) but will instead just
write the integer truncated to 8 bits (as makes sense).

* Use 256byte chunks in ::write template

Reduce stack requirements for templated writes to 256bytes, matching the
size uses in WiFiClient/etc. (from 512bytes).  Reduces the chance of
stack overflow.

* Move write(int) methods up to Print.h

Remove some technical debt by moving the ::write(int/short/long) methods
out of FS and HardwareSerial and up into Print.h.
This commit is contained in:
Earle F. Philhower, III
2019-03-12 13:58:00 -07:00
committed by GitHub
parent 192aaa4291
commit 02f54e85fd
4 changed files with 58 additions and 17 deletions

View File

@ -331,3 +331,31 @@ TEST_CASE("Listfiles.ino example", "[sd]")
REQUIRE(readFileSD("/dir2/dir3/file4") == "bonjour");
}
TEST_CASE("Multisplendored File::writes", "[fs]")
{
SDFS_MOCK_DECLARE();
SDFS.end();
SDFS.setConfig(SDFSConfig(0, SD_SCK_MHZ(1)));
REQUIRE(SDFS.format());
REQUIRE(SD.begin(4));
File f = SD.open("/file.txt", FILE_WRITE);
f.write('a');
f.write(65);
f.write("bbcc");
f.write("theend", 6);
char block[3]={'x','y','z'};
f.write(block, 3);
uint32_t bigone = 0x40404040;
f.write((const uint8_t*)&bigone, 4);
f.close();
REQUIRE(readFileSD("/file.txt") == "aAbbcctheendxyz@@@@");
File g = SD.open("/file.txt", FILE_WRITE);
g.write(0);
g.close();
g = SD.open("/file.txt", FILE_READ);
uint8_t u = 0x66;
g.read(&u, 1);
g.close();
REQUIRE(u == 0);
}