santosh said:
Turning off buffering for stdin in setvbuf() seems to accomplish little
since it's overruled by the OS's buffering. But I can see that it might
be useful for output and non-interactive input streams.
If you don't call it, then the chess engines don't work. If you do
call it then they do. So I would not call that useless. If there were
some compiler that did not honor my buffering request, then I would
switch compilers.
7.19.5.6 The setvbuf function
Synopsis
1 #include <stdio.h>
int setvbuf(FILE * restrict stream,
char * restrict buf,
int mode, size_t size);
Description
2 The setvbuf function may be used only after the stream pointed to by
stream has
been associated with an open file and before any other operation (other
than an
unsuccessful call to setvbuf) is performed on the stream. The argument
mode
determines how stream will be buffered, as follows: _IOFBF causes
input/output to be
fully buffered; _IOLBF causes input/output to be line buffered; _IONBF
causes
input/output to be unbuffered. If buf is not a null pointer, the array
it points to may be
used instead of a buffer allocated by the setvbuf function (see
footnote 230) and the argument size
specifies the size of the array; otherwise, size may determine the size
of a buffer
allocated by the setvbuf function. The contents of the array at any
time are
indeterminate.
Returns
3 The setvbuf function returns zero on success, or nonzero if an
invalid value is given
for mode or if the request cannot be honored.
footnote 230) The buffer has to have a lifetime at least as great as
the open stream, so the stream should be closed
before a buffer that has automatic storage duration is deallocated upon
block exit.
Correct me if I'm wrong but I don't see any limit to the buffer's
allowed size. The value of BUFSIZ is recommended but I don't see why
only tiny buffers are allowed.
The thing could theoretically be huge. But Microsoft set a tiny limit
on it (16K or something nearly as absurd if I recall correctly) so I
just write system specific routines when I want to buffer since I am
going to have to do it anyway.