Skip to content

Commit

Permalink
Fixes bug in FlashFile O_TRUNC handling. (#611)
Browse files Browse the repository at this point in the history
There was a bug in how we interpreted the O_TRUNC in FlashFile::open. We were looking for O_WRONLY in the mode bits but O_WRONLY is actually part of the flags bits.

===

* Fixes bug in FlashFile O_TRUNC handling.

* excludes RDONLY mode from truncating.
  • Loading branch information
balazsracz authored Feb 6, 2022
1 parent 3196adb commit 7d0cdbc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/freertos_drivers/common/FlashFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public:
/// Overrides behavior of open for O_TRUNC.
int open(File *file, const char *path, int flags, int mode) override
{
if ((mode & O_WRONLY) && (flags & O_TRUNC))
if ((flags & O_TRUNC) && ((flags & O_ACCMODE) != O_RDONLY))
{
// erase entire file.
flash_->erase(flashStart_, size_);
Expand Down

0 comments on commit 7d0cdbc

Please sign in to comment.