NuxiNL / cloudlibc

CloudABI's standard C library
BSD 2-Clause "Simplified" License
295 stars 17 forks source link

Odd flushing behavior #30

Open mcandre opened 5 years ago

mcandre commented 5 years ago

I'm used to fprintf() intelligently flushing my output streams, e.g. when writing brief text blurbs to stderr in a Read Eval Print Loop application. However, CloudABI appears to wait until the program is terminating to flush. Could we get the flushing behavior closer to a typical GNU/libc fprintf() implicit flush?

As a workaround, I am doing this for important user feedback sections:

fprintf(console, "blahblahblah\n");

#if defined(__CloudABI__)
    fflush(console);
#endif
EdSchouten commented 5 years ago

Hey! That's because on CloudABI, pipes and TTYs are treated identically. If you want line buffering, just call setvbuf() after opening the stream.

mcandre commented 4 years ago

@EdSchouten Oh, thank you for clarifying!

Would it make sense for the yaml config to offer a tty bool option on fd's? Perhaps this could automatically be enabled for the stdout, stderr streams.