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]

Line buffering on stdout


Hi,

I'm seeing somewhat unexpected behaviour on the following code when
running on a new target I'm porting newlib to:

printf("Enter a string: ");
gets(buf);
printf("You entered: %s\n", buf);

Basically, "Enter a string" is only displayed after I have entered a
string. i.e:

asdf
Enter a string: You entered: asdf

If I change this to:

printf("Enter a string:\n");

Then it works as expected. 

When running on Cygwin, the first program works as I would have
expected. Is this likely to be a problem with my underlying O/S
routines?

I've had a look at the following:

isatty(0) == 1
isatty(1) == 1
fstat(0, &s);
s.st_mode == 20666

Which are all the same as CygWin. Is there anything else? My port
doesn't define HAVE_FCNTL. I notice in __sinit stdout is initialised
with the __SLBF flag. Should I be changing this to __SNBF? If so, how?

stdout->_flags &= ~__SLBF;
stdout->_flags |= __SNBF;

Doesn't seem to have an effect. 

Cheers,
JonB


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