This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Initializing stdio on a powerpc target


How do I initialize stdin, stdout and stderr for new threads?

I've got two PPC processors on my board which each has it's own _reent
structure.  (__DYNAMIC_REENT__ is defined for newlib).  For the first uP,
__getreent() returns _impure_ptr.  On the second processor, __getreent()
returns a pointer to switch_impure which is defined as follows:

struct _reent switch_impure = _REENT_INIT(switch_impure);

The first processor stdio works fine.  However, on the second processor I
have the following problem:

I call setvbuf(stdout, NULL, _IONBF, 0) to make the stream unbuffered.
Subsequent calls to putchar correctly output without buffering, however
calls to printf get buffered if there is not a carriage return at the end of
the string.  So, the following code:

printf("\r\n");
putchar('1');
printf("-Hello-");
putchar('2');
printf(":World:\r\n");
putchar('3');

Creates the following output:
12-Hello-:World:
3

I think that there is a problem with my initialization of switch_impure.
What am I doing wrong?

Thanks,
g.


does not make the stream unbuffered for calls to printf.  If 
2. printf works fine, but putchar sends characters to the _impure_ptr
stdout, instead of switch_impure stdout


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]