mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-11 07:46:09 -07:00
commit
9b952b29eb
1 changed files with 11 additions and 11 deletions
|
@ -27,6 +27,7 @@
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int ukbhit(void)
|
int ukbhit(void)
|
||||||
{
|
{
|
||||||
|
@ -34,19 +35,18 @@ int ukbhit(void)
|
||||||
int error;
|
int error;
|
||||||
static struct termios Otty, Ntty;
|
static struct termios Otty, Ntty;
|
||||||
|
|
||||||
|
if ( tcgetattr(STDIN_FILENO, &Otty) == -1 ) return -1;
|
||||||
if ( tcgetattr( 0, &Otty) == -1 ) return -1;
|
|
||||||
Ntty = Otty;
|
Ntty = Otty;
|
||||||
|
|
||||||
Ntty.c_iflag = 0; /* input mode */
|
Ntty.c_iflag = 0x0000; // input mode
|
||||||
Ntty.c_oflag = 0; /* output mode */
|
Ntty.c_oflag = 0x0000; // output mode
|
||||||
Ntty.c_lflag &= ~ICANON; /* raw mode */
|
Ntty.c_lflag &= ~ICANON; // control mode = raw
|
||||||
Ntty.c_cc[VMIN] = CMIN; /* minimum time to wait */
|
Ntty.c_cc[VMIN] = 1; // return if at least 1 character is in the queue
|
||||||
Ntty.c_cc[VTIME] = CTIME; /* minimum characters to wait for */
|
Ntty.c_cc[VTIME] = 0; // no timeout. Wait forever
|
||||||
|
|
||||||
if (0 == (error = tcsetattr(0, TCSANOW, &Ntty))) {
|
if (0 == (error = tcsetattr(STDIN_FILENO, TCSANOW, &Ntty))) { // set new attributes
|
||||||
error += ioctl(0, FIONREAD, &cnt);
|
error += ioctl(STDIN_FILENO, FIONREAD, &cnt); // get number of characters availabe
|
||||||
error += tcsetattr(0, TCSANOW, &Otty);
|
error += tcsetattr(STDIN_FILENO, TCSANOW, &Otty); // reset attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( error == 0 ? cnt : -1 );
|
return ( error == 0 ? cnt : -1 );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue