Does anyone know why running the following code may cause all future read() calls on that fd (which is stdin) to immediately return 0 instead of blocking for input?
termios newTerminalSettings;
tcgetattr(inFd, &newTerminalSettings);
newTerminalSettings.c_lflag &= ~ICANON;
tcsetattr(inFd, TCSANOW, &newTerminalSettings);
Removing the tcsetattr line makes read() work as expected.
Also tried:
fcntl(inFd, F_SETFL, 0);
with no luck.
Note that I currently have 2 different terminals. Running the app in one of them causes read to return instantly. Running it in the other causes read to block for input. What could it be?
Thanks in advance :-)
Repro source:
#include <iostream>
#include <termios.h>
using namespace std;
int main(void) {
termios newTerminalSettings;
tcgetattr(0, &newTerminalSettings);
newTerminalSettings.c_lflag &= ~ICANON;
tcsetattr(0, TCSANOW, &newTerminalSettings);
char readBuf[5000];
cout << "read returned: " << read(0, readBuf, sizeof(readBuf));
return 0;
}