I'm currently redirecting in a non-portable manner the standard input as:
Code:
freopen ("/dev/tty", "r", stdin);
which /dev/tty always points to the user's terminal. This helps me to read from input in a non-blocking manner.
I can perform well something like:
Code:
while(fgets(buf, sizeof(buf), stdin))
fputs(buf, stdout);
freopen("/dev/tty", "rw", stdin);
// continue with the rest of the code in a non-blocking manner
I'm wondering what would be an alternative to freopen, perhaps using I/O multiplexing. such as select()? or a thread that blocks on reading stdin?
Any alternative sample code would be appreciated.
Platforms: BSDs, Linux