- minor cleanup

This commit is contained in:
Dmytro Bogovych 2018-09-28 19:16:16 +03:00
parent 9cc69508ad
commit 4da6c88f02
2 changed files with 52 additions and 25 deletions

View File

@ -101,13 +101,16 @@ int iosVersion()
#include <sys/select.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <fcntl.h>
int _kbhit()
{
/*
static const int STDIN = 0;
static bool initialized = false;
if (! initialized) {
if (! initialized)
{
// Use termios to turn off line buffering
termios term;
tcgetattr(STDIN, &term);
@ -119,7 +122,31 @@ int _kbhit()
int bytesWaiting;
ioctl(STDIN, FIONREAD, &bytesWaiting);
return bytesWaiting;
return bytesWaiting;*/
static const int STDIN_FILENO = 0;
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
#endif