libgloss/arm/syscalls.c: missing BINARY mode when opening files

Jeff Johnston jjohnstn@redhat.com
Sun Nov 18 22:28:00 GMT 2007


Christophe,

   O_BINARY is an exception to the rule as it is not part of the 
standards that newlib attempts to follow (e.g. POSIX, SUSV2, C89, C99).

   I don't think that ARM should be defining the other things that 
Windows/Cygwin defines (e.g. O_TEXT is not used or needed).  As well, I 
want to ween the shared header files of all the machine and sys 
exceptions in them and provide an easy way to override without having to 
copy all the current information over again so I am following what I did 
for machine/_types.h and have created an alternate patch.

   Basically, I have added a sys/fcntl.h to libc/sys/arm that overrides 
the current definition.  I have created a sys/_default_fcntl.h which is 
included by arm's sys/fcntl.h.  It is then the simple task of adding 
just the O_BINARY flag as needed.  Any other platform can do the same or 
add additional flags just as easily.  I eventually want to handle the 
Cygwin-only stuff the same way.

   Please try the accompanying patch.  If it works and there are no 
objections, I'll check it in.  The ChangeLog is below.

-- Jeff J.

2007-11-15  Jeff Johnston  <jjohnstn@redhat.com>

         * libc/include/sys/_default_fcntl.h: New header file that
         is the default version of sys/fcntl.h.
         * libc/include/sys/fcntl.h: Changed to simply include
         sys/_default_fcntl.h.
         * libc/sys/arm/sys/fcntl.h: New file that includes
         sys/_default_fcntl.h and defines O_BINARY.


Christophe LYON wrote:
> 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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: obinary.patch
Type: text/x-patch
Size: 13532 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20071118/0bed1fb2/attachment.bin>


More information about the Newlib mailing list