From: Keith M. <kei...@us...> - 2008-03-21 22:55:05
|
On Friday 21 March 2008 07:11, Danny Smith wrote: > My understanding is that standard input and output streams are > fully buffered if and only if the streams do not refer to an > interactive or terminal device, as determined by the isatty function. This isn't strictly accurate; here's what the manpages on my GNU/Linux box have to say about it: | The three types of buffering available are unbuffered, block | buffered, and line buffered. When an output stream is unbuffered, | information appears on the destination file or terminal as soon as | written; when it is block buffered many characters are saved up and | written as a block; when it is line buffered characters are saved up | until a newline is output or input is read from any stream attached to | a terminal device (typically stdin). The function fflush(3) may be | used to force the block out early. (See fclose(3).) Normally all | files are block buffered. When the first I/O operation occurs on a | file, malloc(3) is called, and a buffer is obtained. If a stream | refers to a terminal (as stdout normally does) it is line buffered. | The standard error stream stderr is always unbuffered by default. | | The setvbuf() function may be used on any open stream to change its | buffer. > If you redirect to a file or pseudo-tty, then the streams are > buffered. If you redirect to a file, yes. This is not so, in the case of a pseudo-tty, for which isatty *should* return true. However, since Win32 doesn't provide pseudo-ttys, that's fairly immaterial. Earnie's RXVT for MSYS tries to emulate them, using pipes, but unfortunately that has the same effect as redirection to/from files, so isatty inappropriately returns false, leading to problems such as those reported by the OP. Using the native Win32 console, rather than RXVT, results in isatty correctly reporting true, for the standard I/O streams, when they are not redirected to/from files or pipes. Regards, Keith. |