This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
libgloss/arm/syscalls.c: missing BINARY mode when opening files
- From: Christophe LYON <christophe dot lyon at st dot com>
- To: newlib at sourceware dot org
- Date: Thu, 15 Nov 2007 16:45:32 +0100
- Subject: libgloss/arm/syscalls.c: missing BINARY mode when opening files
Hello,
I have been experiencing issues when reading files in the following
configuration:
- compilation with arm-none-eabi-gcc (ie GCC for ARM)
- execution through RVDebug (ie ARM's debugger) under Windows.
After some investigation, I have discovered that in Newlib's _swiopen()
(in libgloss/arm/syscalls.c), there are the following 4 lines:
#ifdef O_BINARY
if (flags & O_BINARY)
aflags |= 1;
#endif
where O_BINARY is NOT defined when cross-compiling for ARM.
Indeed, in newlib/libc/include/sys/fcntl.h, we can see:
#if defined (_WIN32) || defined (__CYGWIN__)
#define _FBINARY 0x10000
#define _FTEXT 0x20000
#define _FNOINHERIT 0x40000
#define O_BINARY _FBINARY
.....
The result is that when opening a file in binary mode, (eg "rb"), the
'binary' flag is discarded before performing the semi-hosting call.
Then, rvdebug interprets this as an open in TEXT mode, which leads to
unpleasant results.
Amusingly, executing from a Linux-hosted rvdebug seems to open in BINARY
mode in the same circumstances (which is not surprising...).
So, there is a discrepancy on ARM's side, but I would also say there is
a bug on Newlib's side.
I propose to add || defined (__arm__) in fcntl.h.
What do you think ?
Thanks,
Christophe.