Skip to content

Commit c6d2c81

Browse files
committed
LocalFileSystem fails to open binary files
Fixes issue #1562 reported by @justbuchanan. When building code with GCC-ARM / newlib, attempting to use the b (binary) mode in a fopen() call would fail. newlib would parse this option and pass it down to the LocalFileSystem open call which didn't like the unexpected O_BINARY flag in openmode. The openmode_to_posix() function in retarget.cpp would never set the O_BINARY flag for the other toolchains but for GCC it would just pass down whatever newlib placed there. This commit masks out the O_BINARY bit so that it never gets passed down to the file system drivers, just as occurs for the other supported toolchains. Test case: FILE *fp = fopen("/local/out.txt", "rb"); I tested that code on mbed LPC1768 and LPC11U24 boards while using GCC_ARM as the toolchain. It failed on both platforms previous to this change and succeeded there after.
1 parent 70c8bcf commit c6d2c81

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libraries/mbed/common/retarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static inline int openmode_to_posix(int openmode) {
122122
if (openmode & _LLIO_APPEND) posix |= O_APPEND;
123123
if (openmode & _LLIO_TRUNC ) posix |= O_TRUNC;
124124
#endif
125-
return posix;
125+
return posix & ~O_BINARY;
126126
}
127127

128128
extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {

0 commit comments

Comments
 (0)