Let's say I have a C program that has the following loop.
while ((c = getchar()) != EOF) {
...
}
This loop seems as if it reads the characters one by one as they are typed on the tty. But then I should not be able to change the characters once they have been inputted, clearly, this does not happen.
That must mean the tty must keep some buffer to keep the values that it has received and not yet pushed to stdin. Once in stdin the characters are read one by one.
Is this right? If so, how can I obtain the chars in this buffer, without them having to go to stdin? I tried using ioctl with FIONREAD, but it doesn't seem to work(the size of the buffer is always zero, even though there are chars in the terminal), and since this data is not in stdin that means methods that read from stdin wouldn't work(These were given as answers to similar questions)