[En-Nut-Discussion] freopen(..)
Bernard Fouché
bernard.fouche at kuantic.com
Fri Oct 28 18:05:45 CEST 2005
Harald Kipp wrote:
> Hi Bernard,
>
> At 11:52 27.10.2005 +0200, you wrote:
>
>> stdout=freopen("uart0","w",stdout);
>
>
> This is used wrongly. The return value should not be
> assigned to stdout, but only checked for failure.
>
freopen() is supposed to give back a FILE *, not just a test value.
Using stdout=freopen(somefile,someflags,stdout); is rather usual since
it allows one to reuse code referencing stdout to send data somewhere
instead of the 'normal' stdout. There is always trouble when a known
function like that has a behavior different from the standard one.
Now I try to read data from uart0. I've tried to use stdout for both ways:
freopen("uart0","r+",stdout); -> I can write but fgetc(stdout) crashes
the application.
I've tried:
freopen("uart0","w",stdout);
freopen("uart0","r",stdin);
fgetc(stdin);
It also crash.
What is the correct way to be able to use streams for bidirectionnal
i/o's with a uart0 ?
Thanks
Bernard
More information about the En-Nut-Discussion
mailing list