File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1495,5 +1495,26 @@ size_t FatFile::write(const void* buf, size_t nbyte) {
1495
1495
return -1 ;
1496
1496
}
1497
1497
1498
+ // -------------------------------------------------------
1499
+ // EFP3 - Match upstream Arduino hack
1500
+ int FatFile::availableSpaceForWrite () {
1501
+ // error if not a normal file or is read-only
1502
+ if (!isWritable () || m_vol->m_blockDev ->isBusy ()) {
1503
+ return 0 ;
1504
+ }
1505
+ // seek to end of file if append flag
1506
+ if ((m_flags & FILE_FLAG_APPEND)) {
1507
+ if (!seekSet (m_fileSize)) {
1508
+ return 0 ;
1509
+ }
1510
+ }
1511
+ uint8_t sectorOfCluster = m_vol->sectorOfCluster (m_curPosition);
1512
+ uint16_t sectorOffset = m_curPosition & m_vol->sectorMask ();
1513
+ if (sectorOfCluster == 0 && sectorOffset == 0 ) {
1514
+ return 0 ;
1515
+ }
1516
+ return m_vol->bytesPerSector () - sectorOffset - 1 ;
1517
+ }
1518
+ // -------------------------------------------------------
1498
1519
1499
1520
}; // namespace sdfat
Original file line number Diff line number Diff line change @@ -937,6 +937,8 @@ class FatFile {
937
937
*
938
938
*/
939
939
size_t write (const void * buf, size_t count);
940
+
941
+ int availableSpaceForWrite ();
940
942
// ------------------------------------------------------------------------------
941
943
#if ENABLE_ARDUINO_SERIAL
942
944
/* * List directory contents.
You can’t perform that action at this time.
0 commit comments