I have searched:
- the standard library (figured the answer isn’t there because there is a dead end of libc_hidden_def which is apparently something that connects to the kernel)
- xfce4-terminal source code
- the Linux kernel
and still failed to find the answer that will explain how read(2) knows that is has to block or not block. Yes, read(2) is not the fuction containing the answer, but it is the starting point.
Here I will draw the timeline of the problem:
- tcsetattr(set VMIN and VTIME to get raw mode or some other combo)
- read(try to read from STDIN)
- ???
- something somewhere checks the termios struct that we have set, and decides whether to keep polling STDIN until a newline comes, until x characters are inside, until x time has passed, or always return whatever is (not) inside
- we get the result of read()