PATCH: Fix ARM problem with freopen
Jeff Johnston
jjohnstn@redhat.com
Tue Jan 6 19:31:00 GMT 2004
Patch checked in. Thanks.
-- Jeff J.
Mark Mitchell wrote:
>Jeff --
>
>I'd like to commit the attached patch to newlib.
>
>The problem was that the current version of remap_handle did not work
>correctly when a standard stream (such as "stdin") was reopend with
>"freopen". Because "open" cleverly keeps the descriptors for the
>standard streams and all other descriptors separate, we can just check
>"STDIN_FILENO" instead.
>
>OK?
>
>--
>Mark Mitchell
>CodeSourcery, LLC
>mark@codesourcery.com
>
>2003-12-29 Mark Mitchell <mark@codesourcery.com>
>
> * libc/sys/arm/syscalls.c (unistd.h): Include it.
> (remap_handle): Use STDIN_FILENO instead of __sfileno(stdin).
> Similarly for stdout and stderr.
>
>Index: libc/sys/arm/syscalls.c
>===================================================================
>RCS file: /cvs/src/src/newlib/libc/sys/arm/syscalls.c,v
>retrieving revision 1.8
>diff -c -5 -p -r1.8 syscalls.c
>*** libc/sys/arm/syscalls.c 6 May 2002 20:46:37 -0000 1.8
>--- libc/sys/arm/syscalls.c 29 Dec 2003 21:07:24 -0000
>***************
>*** 10,19 ****
>--- 10,20 ----
> #include <time.h>
> #include <sys/time.h>
> #include <sys/times.h>
> #include <errno.h>
> #include <reent.h>
>+ #include <unistd.h>
> #include "swi.h"
>
> /* Forward prototypes. */
> int _system _PARAMS ((const char *));
> int _rename _PARAMS ((const char *, const char *));
>*************** remap_handle (int fh)
>*** 123,137 ****
> CHECK_INIT(stdin);
> CHECK_INIT(stdout);
> CHECK_INIT(stderr);
> std_files_checked = 1;
> }
>! if (fh == __sfileno (stdin))
> return monitor_stdin;
>! if (fh == __sfileno (stdout))
> return monitor_stdout;
>! if (fh == __sfileno (stderr))
> return monitor_stderr;
>
> return fh - FILE_HANDLE_OFFSET;
> }
>
>--- 124,138 ----
> CHECK_INIT(stdin);
> CHECK_INIT(stdout);
> CHECK_INIT(stderr);
> std_files_checked = 1;
> }
>! if (fh == STDIN_FILENO)
> return monitor_stdin;
>! if (fh == STDOUT_FILENO)
> return monitor_stdout;
>! if (fh == STDERR_FILENO)
> return monitor_stderr;
>
> return fh - FILE_HANDLE_OFFSET;
> }
>
>
>
More information about the Newlib
mailing list