I'm currently redirecting in a non-portable manner the standard input as:
which /dev/tty always points to the user's terminal. This helps me to read from input in a non-blocking manner.Code:freopen ("/dev/tty", "r", stdin);
I can perform well something like:
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?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
Any alternative sample code would be appreciated.
Platforms: BSDs, Linux