input: make stdin non-blocking for terminal input

getch2.c did not make stdin non-blocking, and relied on only being
called after select() had shown readability. Stop relying on that
assumption and set stdin to non-blocking mode. Hopefully no relevant
platform has problems with this...
This commit is contained in:
Uoti Urpala 2011-04-28 12:52:00 +03:00
parent 3b401fb07f
commit 40234b1a3c
1 changed files with 7 additions and 1 deletions

View File

@ -55,6 +55,7 @@
#endif
#include <unistd.h>
#include <fcntl.h>
#include "mp_fifo.h"
#include "keycodes.h"
@ -277,10 +278,15 @@ struct termios tio_new;
tcgetattr(0,&tio_orig);
tio_new=tio_orig;
tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
tio_new.c_cc[VMIN] = 1;
tio_new.c_cc[VMIN] = 0;
tio_new.c_cc[VTIME] = 0;
tcsetattr(0,TCSANOW,&tio_new);
#endif
/* Setting VMIN above should already make terminal non-blocking; but
* that won't work if stdin is not a real terminal. */
int flags = fcntl(0, F_GETFL);
if (flags != -1)
fcntl(0, F_SETFL, flags | O_NONBLOCK);
getch2_status=1;
}