diff --git a/firmware/common/file.c b/firmware/common/file.c index 82a33ada2d..6d60595ab1 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -83,17 +83,13 @@ int open(const char* pathname, int flags) errno = EMFILE; return -2; } + memset(&openfiles[fd], 0, sizeof (struct filedesc)); - if (flags & O_RDONLY) { - openfiles[fd].write = false; - } - else { - if (flags & (O_RDWR | O_WRONLY)) { - openfiles[fd].write = true; - - if (flags & O_TRUNC) - openfiles[fd].trunc = true; - } + if (flags & (O_RDWR | O_WRONLY)) { + openfiles[fd].write = true; + + if (flags & O_TRUNC) + openfiles[fd].trunc = true; } openfiles[fd].busy = true; diff --git a/firmware/common/file.h b/firmware/common/file.h index 2effe31ac9..bf7ad82ff7 100644 --- a/firmware/common/file.h +++ b/firmware/common/file.h @@ -37,9 +37,9 @@ #define O_RDONLY 0 #define O_WRONLY 1 #define O_RDWR 2 -#define O_CREAT 3 -#define O_APPEND 4 -#define O_TRUNC 5 +#define O_CREAT 4 +#define O_APPEND 8 +#define O_TRUNC 0x10 #endif #if defined(__MINGW32__) && defined(SIMULATOR)