Skip to content

Commit b99cae3

Browse files
committed
fix #276 rename macro FILE_READ/WRITE to enum FILE_O_READ/WRITE
to avoid conflict with other filesystem define
1 parent 9b37e28 commit b99cae3

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Adafruit_LittleFS
4646
// Open the specified file/directory with the supplied mode (e.g. read or
4747
// write, etc). Returns a File object for interacting with the file.
4848
// Note that currently only one file can be open at a time.
49-
Adafruit_LittleFS_Namespace::File open (char const *filename, uint8_t mode = FILE_READ);
49+
Adafruit_LittleFS_Namespace::File open (char const *filename, uint8_t mode = Adafruit_LittleFS_Namespace::FILE_O_READ);
5050

5151
// Methods to determine if the requested file path exists.
5252
bool exists (char const *filepath);

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ File::File (char const *filename, uint8_t mode, Adafruit_LittleFS &fs)
5151

5252
bool File::_open_file (char const *filepath, uint8_t mode)
5353
{
54-
int flags = (mode == FILE_READ) ? LFS_O_RDONLY :
55-
(mode == FILE_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0;
54+
int flags = (mode == FILE_O_READ) ? LFS_O_RDONLY :
55+
(mode == FILE_O_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0;
5656

5757
if ( flags )
5858
{
@@ -69,7 +69,7 @@ bool File::_open_file (char const *filepath, uint8_t mode)
6969
}
7070

7171
// move to end of file
72-
if ( mode == FILE_WRITE ) lfs_file_seek(_fs->getFS(), _file, 0, LFS_SEEK_END);
72+
if ( mode == FILE_O_WRITE ) lfs_file_seek(_fs->getFS(), _file, 0, LFS_SEEK_END);
7373

7474
_is_dir = false;
7575
}
@@ -116,8 +116,8 @@ bool File::open (char const *filepath, uint8_t mode)
116116
}
117117
else if ( LFS_ERR_NOENT == rc )
118118
{
119-
// file not existed, only proceed with FILE_WRITE mode
120-
if ( mode == FILE_WRITE ) ret = _open_file(filepath, mode);
119+
// file not existed, only proceed with FILE_O_WRITE mode
120+
if ( mode == FILE_O_WRITE ) ret = _open_file(filepath, mode);
121121
}
122122
else
123123
{

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@
2525
#ifndef ADAFRUIT_LITTLEFS_FILE_H_
2626
#define ADAFRUIT_LITTLEFS_FILE_H_
2727

28-
#define FILE_READ 0
29-
#define FILE_WRITE 1
30-
3128
// Forward declaration
3229
class Adafruit_LittleFS;
3330

3431
namespace Adafruit_LittleFS_Namespace
3532
{
3633

34+
// avoid conflict with other FileSystem FILE_READ/FILE_WRITE
35+
enum
36+
{
37+
FILE_O_READ = 0,
38+
FILE_O_WRITE = 1,
39+
};
40+
3741
class File : public Stream
3842
{
3943
public:
@@ -69,7 +73,7 @@ class File : public Stream
6973
char const* name (void);
7074

7175
bool isDirectory (void);
72-
File openNextFile (uint8_t mode = FILE_READ);
76+
File openNextFile (uint8_t mode = FILE_O_READ);
7377
void rewindDirectory (void);
7478

7579
private:

libraries/BLEHomekit/src/crypto/crypto.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
//#include <pstorage.h>
1414
//#include <app_scheduler.h>
1515
#include <nrf_soc.h>
16-
#include "Bluefruit_FileIO.h"
16+
#include <Adafruit_LittleFS.h>
17+
#include <InternalFileSystem.h>
1718
#include "utility/debug.h"
1819

1920
#include "rtos.h"
2021
#include "utility/AdaCallback.h"
2122

2223
#include "crypto.h"
2324

25+
using namespace Adafruit_LittleFS_Namespace;
26+
2427
#define CRYPTO_INSTANCE 2 // Change this to force key regeneration on next run
2528

2629
crypto_keys_t crypto_keys;
@@ -108,7 +111,7 @@ static uint8_t crypto_loadKeys(void)
108111

109112
uint32_t keylen = sizeof(keys);
110113

111-
File file(CRYPTO_KEYFILE, FILE_READ, InternalFS);
114+
File file(CRYPTO_KEYFILE, FILE_O_READ, InternalFS);
112115
VERIFY(file, 0);
113116

114117
keylen = file.read(&keys, keylen);
@@ -162,7 +165,7 @@ void crypto_storeKeys(void)
162165
keys.valid0 = 0x55;
163166
keys.valid1 = 0xAA;
164167

165-
File file(CRYPTO_KEYFILE, FILE_WRITE, InternalFS);
168+
File file(CRYPTO_KEYFILE, FILE_O_WRITE, InternalFS);
166169
VERIFY(file,);
167170

168171
file.write(&keys, sizeof(keys));

libraries/Bluefruit52Lib/examples/Projects/homekit/homekit_lightbulb/homekit_lightbulb.ino.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void setup()
124124
Bluefruit.setName("Bluefruit52");
125125

126126
//InternalFS.remove(CRYPTO_KEYFILE);
127-
//File file(CRYPTO_KEYFILE, FILE_WRITE, InternalFS);
127+
//File file(CRYPTO_KEYFILE, FILE_O_WRITE, InternalFS);
128128
//file.write(&test_keys, sizeof(test_keys));
129129
//file.close();
130130

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bk
104104
// delete if file already exists
105105
if ( InternalFS.exists(filename) ) InternalFS.remove(filename);
106106

107-
File file(filename, FILE_WRITE, InternalFS);
107+
File file(filename, FILE_O_WRITE, InternalFS);
108108
VERIFY(file,);
109109

110110
//------------- save keys -------------//
@@ -141,7 +141,7 @@ bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys)
141141
char filename[BOND_FNAME_LEN];
142142
get_fname(filename, role, ediv);
143143

144-
File file(filename, FILE_READ, InternalFS);
144+
File file(filename, FILE_O_READ, InternalFS);
145145
VERIFY(file);
146146

147147
int keylen = file.read();
@@ -171,7 +171,7 @@ static void bond_save_cccd_dfr (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
171171
char filename[BOND_FNAME_LEN];
172172
get_fname(filename, role, ediv);
173173

174-
File file(filename, FILE_WRITE, InternalFS);
174+
File file(filename, FILE_O_WRITE, InternalFS);
175175
VERIFY(file,);
176176

177177
file.seek(0); // write mode start at the end, seek to beginning
@@ -204,7 +204,7 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)
204204
char filename[BOND_FNAME_LEN];
205205
get_fname(filename, role, ediv);
206206

207-
File file(filename, FILE_READ, InternalFS);
207+
File file(filename, FILE_O_READ, InternalFS);
208208

209209
if ( file )
210210
{
@@ -241,10 +241,10 @@ void bond_print_list(uint8_t role)
241241
{
242242
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
243243

244-
File dir(dpath, FILE_READ, InternalFS);
244+
File dir(dpath, FILE_O_READ, InternalFS);
245245
File file(InternalFS);
246246

247-
while ( (file = dir.openNextFile(FILE_READ)) )
247+
while ( (file = dir.openNextFile(FILE_O_READ)) )
248248
{
249249
if ( !file.isDirectory() && bdata_skip_field(&file) ) // skip key
250250
{
@@ -272,10 +272,10 @@ bool bond_find_cntr(ble_gap_addr_t const * addr, bond_keys_t* bkeys)
272272
{
273273
bool found = false;
274274

275-
File dir(BOND_DIR_CNTR, FILE_READ, InternalFS);
275+
File dir(BOND_DIR_CNTR, FILE_O_READ, InternalFS);
276276
File file(InternalFS);
277277

278-
while ( (file = dir.openNextFile(FILE_READ)) )
278+
while ( (file = dir.openNextFile(FILE_O_READ)) )
279279
{
280280
// Read bond data of each stored file
281281
int keylen = file.read();

libraries/InternalFileSytem/examples/Internal_ListFiles/Internal_ListFiles.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void loop()
7070
void printTreeDir(const char* cwd, uint8_t level)
7171
{
7272
// Open the input folder
73-
File dir(cwd, FILE_READ, InternalFS);
73+
File dir(cwd, FILE_O_READ, InternalFS);
7474

7575
// Print root
7676
if (level == 0) Serial.println("root");
@@ -79,7 +79,7 @@ void printTreeDir(const char* cwd, uint8_t level)
7979
File item(InternalFS);
8080

8181
// Loop through the directory
82-
while( (item = dir.openNextFile(FILE_READ)) )
82+
while( (item = dir.openNextFile(FILE_O_READ)) )
8383
{
8484
// Indentation according to dir level
8585
for(int i=0; i<level; i++) Serial.print("| ");

libraries/InternalFileSytem/examples/Internal_ReadWrite/Internal_ReadWrite.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void setup()
4444
// Initialize Internal File System
4545
InternalFS.begin();
4646

47-
file.open(FILENAME, FILE_READ);
47+
file.open(FILENAME, FILE_O_READ);
4848

4949
// file existed
5050
if ( file )
@@ -62,7 +62,7 @@ void setup()
6262
{
6363
Serial.print("Open " FILENAME " file to write ... ");
6464

65-
if( file.open(FILENAME, FILE_WRITE) )
65+
if( file.open(FILENAME, FILE_O_WRITE) )
6666
{
6767
Serial.println("OK");
6868
file.write(CONTENTS, strlen(CONTENTS));

0 commit comments

Comments
 (0)