Buffered and Unbuffered inputs in C
buffer, c, input
Solution
All `stdio.h` functions for reading from a `FILE` may exhibit either "buffered" or "unbuffered" behavior, and either "echoing" or "non-echoing" behavior. What controls these things is not which function you use, but settings on the stream and/or its underlying file descriptor.
The standard library function `setvbuf` can be used to enable or disable buffering of input (and output) by the C library. This has no effect on buffering by the operating system. There are three possible modes: "fully buffered" (read or write in substantial chunks); "line buffered" (buffer until a `'\n'` character is read or written, but not beyond that); and "unbuffered" (all reads and writes go to the OS immediately).
The default buffering for new `FILE` objects (including `stdin` and friends) is implementation-defined. Unixy C libraries generally default all `FILE`s to fully buffered, with two exceptions. `stderr` defaults to unbuffered. For any other `FILE`, if `setvbuf` has not been used on it at the time of the first actual read or write, and `isatty` is true for the underlying file descriptor, then the `FILE` becomes line-buffered.
Some C libraries provide extension functions, e.g. `__flbf` and friends on Linux and Solaris, for reading back some of the settings controlled by `setvbuf`. Keep in mind that, as described above, the buffering mode can change upon the first actual read or write, if it hasn't been explicitly set.
If input is from a file, `setvbuf` is the only knob you have. If input is from some sort of communication channel, there may be other knobs:
On POSIX-conformant systems (read "everything except Windows"), a program can request any of several different modes for terminal input. Of these, the most important distinction to make is between "canonical" and "noncanonical". A terminal in canonical mode exhibits both buffering and echoing. (This buffering is separate from the buffering the C library may do if `setvbuf` has not been used to disable it.) Non-canonical mode allows you to toggle buffering and echoing separately. The low-level POSIX terminal interface is extensive, complicated, and allows you to both read and write all of these settings.
If you think you want to put the terminal in a non-canonical mode, before writing a bunch of code against the low-level POSIX API for doing so, you should first consider whether the `readline` or `ncurses` library would make your life easier.
If you are reading from a pipe, you are at the mercy of whoever is writing to it; you cannot control the size of the chunks you get.
If you are reading from a socket, you may be able to exercise some control over the size of the chunks you get by careful use of `recvmsg`, but there are no guarantees.
I don't know how it is on Windows.
Problem
Is there any way to figure out whether the `input` is `buffered` or `unbuffered` (Apart from manual pages.)? Cant we figure out by looking at the names of the functions? Also for `echoing` and `nonechoing...` For quick reference where to find the list which has the details of `Buffered`, `Unbuffered`, `echoing` and `nonechoing` inputs?