Skip to content

Commit 202d38b

Browse files
committed
boolean -> bool
1 parent 143dbae commit 202d38b

File tree

3 files changed

+49
-51
lines changed

3 files changed

+49
-51
lines changed

hardware/esp8266com/esp8266/cores/esp8266/FileSystem.cpp

+26-21
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,46 @@
2121
#include "FileSystem.h"
2222
#include "Arduino.h"
2323

24-
boolean FSClass::mount(){
25-
if(_mounted) return true;
24+
bool FSClass::mount() {
25+
if (_mounted)
26+
return true;
27+
2628
_mounted = spiffs_mount();
2729
return _mounted;
2830
}
2931

30-
void FSClass::unmount(){
31-
if(!_mounted) return;
32+
void FSClass::unmount() {
33+
if (!_mounted)
34+
return;
35+
3236
spiffs_unmount();
3337
_mounted = false;
3438
}
3539

36-
boolean FSClass::format(){
40+
bool FSClass::format() {
3741
return spiffs_format();
3842
}
3943

40-
boolean FSClass::exists(const char *filename){
44+
bool FSClass::exists(const char *filename) {
4145
spiffs_stat stat = {0};
42-
if (SPIFFS_stat(&_filesystemStorageHandle, filename, &stat) < 0) return false;
46+
if (SPIFFS_stat(&_filesystemStorageHandle, filename, &stat) < 0)
47+
return false;
4348
return stat.name[0] != '\0';
4449
}
4550

46-
boolean FSClass::create(const char *filepath){
51+
bool FSClass::create(const char *filepath){
4752
return SPIFFS_creat(&_filesystemStorageHandle, filepath, 0) == 0;
4853
}
4954

50-
boolean FSClass::remove(const char *filepath){
55+
bool FSClass::remove(const char *filepath){
5156
return SPIFFS_remove(&_filesystemStorageHandle, filepath) == 0;
5257
}
5358

54-
boolean FSClass::rename(const char *filename, const char *newname){
59+
bool FSClass::rename(const char *filename, const char *newname) {
5560
return SPIFFS_rename(&_filesystemStorageHandle, filename, newname) == 0;
5661
}
5762

58-
FSFile FSClass::open(const char *filename, uint8_t mode){
63+
FSFile FSClass::open(const char *filename, uint8_t mode) {
5964
int repeats = 0;
6065
bool notExist;
6166
bool canRecreate = (mode & SPIFFS_CREAT) == SPIFFS_CREAT;
@@ -81,25 +86,25 @@ FSFile FSClass::open(const char *filename, uint8_t mode){
8186

8287
FSClass FS;
8388

84-
FSFile::FSFile(){
89+
FSFile::FSFile() {
8590
_file = 0;
8691
_stats = {0};
8792
}
8893

89-
FSFile::FSFile(file_t f){
94+
FSFile::FSFile(file_t f) {
9095
_file = f;
9196
if(SPIFFS_fstat(&_filesystemStorageHandle, _file, &_stats) != 0){
9297
debugf("mount errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
9398
}
9499
}
95100

96-
void FSFile::close(){
101+
void FSFile::close() {
97102
if (! _file) return;
98103
SPIFFS_close(&_filesystemStorageHandle, _file);
99104
_file = 0;
100105
}
101106

102-
uint32_t FSFile::size(){
107+
uint32_t FSFile::size() {
103108
if(! _file) return 0;
104109
uint32_t pos = SPIFFS_tell(&_filesystemStorageHandle, _file);
105110
SPIFFS_lseek(&_filesystemStorageHandle, _file, 0, SPIFFS_SEEK_END);
@@ -108,31 +113,31 @@ uint32_t FSFile::size(){
108113
return size;
109114
}
110115

111-
uint32_t FSFile::seek(uint32_t pos){
116+
uint32_t FSFile::seek(uint32_t pos) {
112117
if (! _file) return 0;
113118
return SPIFFS_lseek(&_filesystemStorageHandle, _file, pos, SPIFFS_SEEK_SET);
114119
}
115120

116-
uint32_t FSFile::position(){
121+
uint32_t FSFile::position() {
117122
if (! _file) return 0;
118123
return SPIFFS_tell(&_filesystemStorageHandle, _file);
119124
}
120125

121-
boolean FSFile::eof(){
126+
bool FSFile::eof() {
122127
if (! _file) return 0;
123128
return SPIFFS_eof(&_filesystemStorageHandle, _file);
124129
}
125130

126-
boolean FSFile::isDirectory(void){
131+
bool FSFile::isDirectory(void) {
127132
return false;
128133
}
129134

130-
int FSFile::read(void *buf, uint16_t nbyte){
135+
int FSFile::read(void *buf, uint16_t nbyte) {
131136
if (! _file) return -1;
132137
return SPIFFS_read(&_filesystemStorageHandle, _file, buf, nbyte);
133138
}
134139

135-
int FSFile::read(){
140+
int FSFile::read() {
136141
if (! _file) return -1;
137142
int val;
138143
if(SPIFFS_read(&_filesystemStorageHandle, _file, &val, 1) != 1) return -1;

hardware/esp8266com/esp8266/cores/esp8266/FileSystem.h

+23-28
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class String;
2929
#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC)
3030

3131
class FSFile : public Stream {
32-
private:
32+
private:
3333
spiffs_stat _stats;
3434
file_t _file;
3535

@@ -47,34 +47,29 @@ class FSFile : public Stream {
4747
uint32_t remove();
4848
uint32_t position();
4949
uint32_t size();
50-
boolean eof();
50+
bool eof();
5151
void close();
5252
int lastError();
5353
void clearError();
54-
operator bool(){ return _file > 0; }
54+
operator bool() { return _file > 0; }
5555
char * name();
56-
boolean isDirectory(void);
56+
bool isDirectory(void);
5757

5858
template<typename T> size_t write(T &src){
59-
uint8_t obuf[64];
60-
size_t doneLen = 0;
61-
size_t sentLen;
62-
int i;
63-
64-
while (src.available() > 64){
65-
src.read(obuf, 64);
66-
sentLen = write(obuf, 64);
67-
doneLen = doneLen + sentLen;
68-
if(sentLen != 64){
69-
return doneLen;
59+
const size_t bufferSize = 64;
60+
uint8_t obuf[bufferSize];
61+
size_t bytesWritten = 0;
62+
while (true){
63+
size_t available = src.available();
64+
size_t willWrite = (available < bufferSize) ? available : bufferSize;
65+
src.read(obuf, willWrite);
66+
size_t cb = write(obuf, willWrite);
67+
bytesWritten += cb;
68+
if (cb != willWrite) {
69+
return bytesWritten;
7070
}
7171
}
72-
73-
size_t leftLen = src.available();
74-
src.read(obuf, leftLen);
75-
sentLen = write(obuf, leftLen);
76-
doneLen = doneLen + sentLen;
77-
return doneLen;
72+
return bytesWritten;
7873
}
7974

8075
using Print::write;
@@ -83,16 +78,16 @@ class FSFile : public Stream {
8378
class FSClass {
8479

8580
private:
86-
boolean _mounted;
81+
bool _mounted;
8782

8883
public:
89-
boolean mount();
84+
bool mount();
9085
void unmount();
91-
boolean format();
92-
boolean exists(const char *filename);
93-
boolean create(const char *filepath);
94-
boolean remove(const char *filepath);
95-
boolean rename(const char *filename, const char *newname);
86+
bool format();
87+
bool exists(const char *filename);
88+
bool create(const char *filepath);
89+
bool remove(const char *filepath);
90+
bool rename(const char *filename, const char *newname);
9691

9792
FSFile open(const char *filename, uint8_t mode = FSFILE_READ);
9893

hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs.h

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
extern "C" {
1313
#endif
1414

15-
//#include "c_stdio.h"
16-
#include <user_config.h>
1715
#include "spiffs_config.h"
1816
#include "flashmem.h"
1917

0 commit comments

Comments
 (0)