Added error when opening multiple files with a statically allocated buffer

Opening multiple files simultaneously is not supported without dynamic memory,
but the previous behaviour would just let the files overwrite each other, which
could lead to bad errors down the line

found by husigeza
This commit is contained in:
Christopher Haster
2018-04-29 16:45:14 +03:00
parent 015b86bc51
commit c5e2b335d6

4
lfs.c
View File

@@ -1335,6 +1335,10 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
// allocate buffer if needed
file->cache.block = 0xffffffff;
if (lfs->cfg->file_buffer) {
if (lfs->files) {
// already in use
return LFS_ERR_NOMEM;
}
file->cache.buffer = lfs->cfg->file_buffer;
} else if ((file->flags & 3) == LFS_O_RDONLY) {
file->cache.buffer = lfs_malloc(lfs->cfg->read_size);