Added possibility to open multiple files with LFS_NO_MALLOC enabled.

This commit is contained in:
Damien George
2018-06-08 11:27:27 +10:00
committed by Christopher Haster
parent f94d233deb
commit 97711d78c4
2 changed files with 6 additions and 3 deletions

7
lfs.c
View File

@@ -1283,7 +1283,7 @@ static int lfs_ctz_traverse(lfs_t *lfs,
/// Top level file operations ///
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags) {
const char *path, int flags, void *file_buffer) {
// deorphan if we haven't yet, needed at most once after poweron
if ((flags & 3) != LFS_O_RDONLY && !lfs->deorphaned) {
int err = lfs_deorphan(lfs);
@@ -1340,7 +1340,10 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
}
// allocate buffer if needed
if (lfs->cfg->file_buffer) {
file->cache.block = 0xffffffff;
if (file_buffer) {
file->cache.buffer = file_buffer;
} else if (lfs->cfg->file_buffer) {
if (lfs->files) {
// already in use
return LFS_ERR_NOMEM;