Skip to content

Commit 3624d12

Browse files
committed
fix esp8266/rp2040 compilation errors
1 parent f127b4d commit 3624d12

File tree

5 files changed

+38
-30
lines changed

5 files changed

+38
-30
lines changed

src/ESP32-targz-lib.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,6 @@ __attribute__((unused)) static uint64_t targzTotalBytesFn() {
227227

228228
#define FOLDER_SEPARATOR "/"
229229

230-
#ifndef FILE_READ
231-
#define FILE_READ "r"
232-
#endif
233-
#ifndef FILE_WRITE
234-
#define FILE_WRITE "w+"
235-
#endif
236-
237230
#ifndef SPI_FLASH_SEC_SIZE
238231
#define SPI_FLASH_SEC_SIZE 4096
239232
#endif

src/libpacker/LibPacker.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ namespace LZPacker
551551
log_d("Stream to file (source=%d bytes)", srcLen);
552552
if( !srcStream || srcLen>0 || !dstFS || !dstFilename)
553553
return 0;
554-
fs_File dstFile = dstFS->open(dstFilename, FILE_WRITE);
554+
fs_File dstFile = dstFS->open(dstFilename, fs_file_write);
555555
if( !dstFile )
556556
return 0;
557557
auto ret = LZPacker::compress(srcStream, srcLen, &dstFile);
@@ -565,7 +565,7 @@ namespace LZPacker
565565
{
566566
if( !srcFS || !srcFilename || !dstFS || !dstFilename)
567567
return 0;
568-
fs_File srcFile = srcFS->open(srcFilename, FILE_READ);
568+
fs_File srcFile = srcFS->open(srcFilename, fs_file_read);
569569
if(!srcFile)
570570
return 0;
571571
auto ret = LZPacker::compress( &srcFile, srcFile.size(), dstFS, dstFilename);
@@ -579,7 +579,7 @@ namespace LZPacker
579579
{
580580
if( !srcFS || !srcFilename || !dstStream)
581581
return 0;
582-
fs_File srcFile = srcFS->open(srcFilename, FILE_READ);
582+
fs_File srcFile = srcFS->open(srcFilename, fs_file_read);
583583
if(!srcFile)
584584
return 0;
585585
log_d("File to stream (source=%d bytes)", srcFile.size());
@@ -666,15 +666,15 @@ namespace TarPacker
666666
log_v("io::open(%s, mode=%s)", filename, mode);
667667
if( String(mode) == "r" ) {
668668
flagStr = "r";
669-
fileRO = fs->open(filename, FILE_READ);
669+
fileRO = fs->open(filename, fs_file_read);
670670
if(!fileRO) {
671671
log_e("Unable to open %s for reading", filename);
672672
return (void*)-1;
673673
}
674674
retPtr = &fileRO;
675675
} else {
676676
flagStr = "w";
677-
fileRW = fs->open(filename, FILE_WRITE);
677+
fileRW = fs->open(filename, fs_file_write);
678678
if(!fileRW) {
679679
log_e("Unable to open %s for writing", filename);
680680
return (void*)-1;
@@ -703,7 +703,7 @@ namespace TarPacker
703703
struct_stat_t *s = (struct_stat_t *)_stat;
704704
static int inode_num = 0;
705705

706-
fs_File f = fs->open(path, FILE_READ);
706+
fs_File f = fs->open(path, fs_file_read);
707707
if(!f) {
708708
log_e("Unable to open %s for stat", path);
709709
return -1;
@@ -961,7 +961,7 @@ namespace TarPacker
961961

962962
int pack_files(fs_FS *srcFS, std::vector<dir_entity_t> dirEntities, fs_FS *dstFS, const char*tar_output_file_path, const char* tar_prefix)
963963
{
964-
auto tar = dstFS->open(tar_output_file_path, FILE_WRITE);
964+
auto tar = dstFS->open(tar_output_file_path, fs_file_write);
965965
if(!tar)
966966
return -1;
967967
auto ret = pack_files(srcFS, dirEntities, &tar, tar_prefix);
@@ -985,7 +985,7 @@ namespace TarGzPacker
985985
// tar-to-gz compression from files/folders list
986986
int compress(fs_FS *srcFS, std::vector<dir_entity_t> dirEntities, fs_FS *dstFS, const char* tgz_name, const char* tar_prefix)
987987
{
988-
auto dstFile = dstFS->open(tgz_name, FILE_WRITE);
988+
auto dstFile = dstFS->open(tgz_name, fs_file_write);
989989
if(!dstFile) {
990990
log_e("Can't open %s for writing", tgz_name);
991991
return -1;

src/libpacker/LibPacker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ namespace TAR
168168
assert(fs);
169169
assert(dirname);
170170

171-
File root = fs->open(dirname, FILE_READ);
171+
File root = fs->open(dirname, fs_file_read);
172172
if (!root) {
173173
log_e("Failed to open directory %s", dirname);
174174
return;

src/libunpacker/LibUnpacker.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void BaseUnpacker::hexDumpData( const char* buff, size_t buffsize, uint32_t outp
387387
// show the contents of a given file as a hex dump
388388
void BaseUnpacker::hexDumpFile( fs_FS &fs, const char* filename, uint32_t output_size )
389389
{
390-
File binFile = fs.open( filename, FILE_READ );
390+
File binFile = fs.open( filename, fs_file_read );
391391
//log_w("File size : %d", binFile.size() );
392392
// only dump small files
393393
if( binFile.size() > 0 ) {
@@ -412,7 +412,7 @@ void BaseUnpacker::hexDumpFile( fs_FS &fs, const char* filename, uint32_t output
412412

413413
void BaseUnpacker::tarGzListDir( fs_FS &fs, const char * dirName, uint8_t levels, bool hexDump )
414414
{
415-
File root = fs.open( dirName, FILE_READ );
415+
File root = fs.open( dirName, fs_file_read );
416416
if( !root ) {
417417
log_e("[ERROR] in tarGzListDir: Can't open %s dir", dirName );
418418
if( halt_on_error() ) targz_system_halt();
@@ -482,7 +482,7 @@ void BaseUnpacker::hexDumpFile( fs_FS &fs, const char* filename, uint32_t output
482482
//void( hexDump ); // not used (yet?) with ESP82
483483
Serial.printf("Listing directory %s with level %d\n", dirname, levels);
484484

485-
File root = fs.open(dirname, FILE_READ);
485+
File root = fs.open(dirname, fs_file_read);
486486
if( !root.isDirectory() ){
487487
log_e( "%s is not a directory", dirname );
488488
return;
@@ -640,7 +640,7 @@ int TarUnpacker::tarHeaderCallBack( TAR::header_translated_t *header, CC_UNUSED
640640
if( tarFS->exists( tar_file_path ) ) {
641641
// file will be truncated
642642
/*
643-
untarredFile = tarFS->open( file_path, FILE_READ );
643+
untarredFile = tarFS->open( file_path, fs_file_read );
644644
bool isdir = untarredFile.isDirectory();
645645
untarredFile.close();
646646
if( isdir ) {
@@ -665,7 +665,7 @@ int TarUnpacker::tarHeaderCallBack( TAR::header_translated_t *header, CC_UNUSED
665665
log_v("[TAR] Creating %s", tar_file_path);
666666
}
667667

668-
untarredFile = tarFS->open(tar_file_path, FILE_WRITE);
668+
untarredFile = tarFS->open(tar_file_path, fs_file_wplus);
669669
if(!untarredFile) {
670670
log_e("[ERROR] in tarHeaderCallBack: Could not open [%s] for write, filesystem full?", tar_file_path);
671671
setError( ESP32_TARGZ_FS_ERROR );
@@ -738,7 +738,7 @@ int TarUnpacker::tarEndCallBack( TAR::header_translated_t *header, CC_UNUSED int
738738
return ESP32_TARGZ_FS_WRITE_ERROR;
739739
}
740740
// health check 3: reopen file to check size on filesystem
741-
untarredFile = tarFS->open(tar_file_path, FILE_READ);
741+
untarredFile = tarFS->open(tar_file_path, fs_file_read);
742742
size_t tmpsize = untarredFile.size();
743743
if( !untarredFile ) {
744744
log_e("[TAR ERROR] Failed to re-open %s for size reading", tar_file_path);
@@ -1015,7 +1015,7 @@ bool TarUnpacker::tarExpander( fs_FS &sourceFS, const char* fileName, fs_FS &des
10151015
setError( ESP32_TARGZ_FS_ERROR );
10161016
return false;
10171017
}
1018-
fs_File tarFile = sourceFS.open( fileName, FILE_READ );
1018+
fs_File tarFile = sourceFS.open( fileName, fs_file_read );
10191019
return tarStreamExpander( (Stream*)&tarFile, tarFile.size(), destFS, destFolder );
10201020
}
10211021

@@ -1477,7 +1477,7 @@ bool GzUnpacker::gzExpander( fs_FS sourceFS, const char* sourceFile, fs_FS destF
14771477
if(tgzLogger)
14781478
tgzLogger("[GZ] Expanding %s to %s\n", sourceFile, destFile );
14791479

1480-
fs_File gz = sourceFS.open( sourceFile, FILE_READ );
1480+
fs_File gz = sourceFS.open( sourceFile, fs_file_read );
14811481
if( !gzProgressCallback ) {
14821482
setGzProgressCallback( defaultProgressCallback );
14831483
}
@@ -1493,7 +1493,7 @@ bool GzUnpacker::gzExpander( fs_FS sourceFS, const char* sourceFile, fs_FS destF
14931493
log_v("[GZ INFO] Deleting %s as it is in the way", destFile);
14941494
destFS.remove( destFile );
14951495
}
1496-
fs_File outfile = destFS.open( destFile, FILE_WRITE );
1496+
fs_File outfile = destFS.open( destFile, fs_file_wplus );
14971497
if(!outfile) {
14981498
log_e("[GZ ERROR] in gzExpander: cannot create destination file, no space left on device ?");
14991499
gz.close();
@@ -1523,7 +1523,7 @@ bool GzUnpacker::gzExpander( fs_FS sourceFS, const char* sourceFile, fs_FS destF
15231523
log_v("uzLib expander finished!");
15241524

15251525
/*
1526-
outfile = destFS.open( destFile, FILE_READ );
1526+
outfile = destFS.open( destFile, fs_file_read );
15271527
log_d("Expanded %s to %s (%d bytes)", sourceFile, destFile, outfile.size() );
15281528
outfile.close();
15291529
*/
@@ -1591,7 +1591,7 @@ bool GzUnpacker::gzStreamExpander( Stream* sourceStream, fs_FS destFS, const cha
15911591
log_v("[GZ INFO] Deleting %s as it is in the way", destFile);
15921592
destFS.remove( destFile );
15931593
}
1594-
fs_File outFile = destFS.open(destFile, FILE_WRITE);
1594+
fs_File outFile = destFS.open(destFile, fs_file_wplus);
15951595
if(!outFile) {
15961596
log_e("[GZ ERROR] in gzExpander: cannot create destination file, no space left on device ?");
15971597
setError( ESP32_TARGZ_UZLIB_INVALID_FILE );
@@ -1619,7 +1619,7 @@ bool GzUnpacker::gzStreamExpander( Stream* sourceStream, fs_FS destFS, const cha
16191619
log_v("uzLib expander finished!");
16201620

16211621
/*
1622-
outfile = destFS.open( destFile, FILE_READ );
1622+
outfile = destFS.open( destFile, fs_file_read );
16231623
log_d("Expanded %s to %s (%d bytes)", sourceFile, destFile, outfile.size() );
16241624
outfile.close();
16251625
*/
@@ -1723,7 +1723,7 @@ bool GzUnpacker::gzStreamExpander( Stream *stream, size_t gz_size )
17231723
return false;
17241724
}
17251725
log_v("uzLib SPIFFS Updater start!");
1726-
fs_File gz = fs.open( gz_filename, FILE_READ );
1726+
fs_File gz = fs.open( gz_filename, fs_file_read );
17271727
#if defined ESP8266
17281728
int update_size = gz.size();
17291729
#endif
@@ -2069,7 +2069,7 @@ bool TarGzUnpacker::tarGzExpanderNoTempFile( fs_FS sourceFS, const char* sourceF
20692069
setError( ESP32_TARGZ_UZLIB_INVALID_FILE );
20702070
return false;
20712071
}
2072-
fs_File gz = sourceFS.open( sourceFile, FILE_READ );
2072+
fs_File gz = sourceFS.open( sourceFile, fs_file_read );
20732073

20742074
if(tgzLogger)
20752075
tgzLogger("[TGZ] Will direct-expand %s to %s\n", sourceFile, destFolder );

src/types/esp32_targz_types.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,24 @@ typedef void (*genericLoggerCallback)( const char* format, ... ); // same behavi
7070
#define fs_SeekMode SeekMode
7171
#define fs_SeekSet SeekSet
7272

73+
#define fs_file_read FILE_READ
74+
#define fs_file_write FILE_WRITE
75+
#define fs_file_wplus FILE_WRITE_BEGIN
76+
7377

7478
#else
7579

80+
#ifndef FILE_READ
81+
#define FILE_READ "r"
82+
#endif
83+
#ifndef FILE_WRITE
84+
#define FILE_WRITE "w+"
85+
#endif
86+
87+
#define fs_file_read FILE_READ
88+
#define fs_file_write FILE_WRITE
89+
#define fs_file_wplus FILE_WRITE_BEGIN
90+
7691
#define fs_FS fs::FS
7792
#define fs_File fs::File
7893
#define fs_SeekMode fs::SeekMode

0 commit comments

Comments
 (0)