* fhandler_console.cc (fhandler_console::ioctl): Fetch console events

using PeekConsoleInput and return only key down events in buf.
	* fhandler_tty.cc (fhandler_pty_slave::ioctl): Always return EINVAL
	if PeekNamedPipe fails.
	(fhandler_pty_master::ioctl): Ditto.
This commit is contained in:
Corinna Vinschen
2011-07-25 15:19:35 +00:00
parent 7d4b10de81
commit f4fc0c59e3
3 changed files with 21 additions and 5 deletions

View File

@@ -892,13 +892,21 @@ fhandler_console::ioctl (unsigned int cmd, void *buf)
return -1;
case FIONREAD:
{
/* Per MSDN, max size of buffer required is below 64K. */
#define INREC_SIZE (65536 / sizeof (INPUT_RECORD))
DWORD n;
if (!GetNumberOfConsoleInputEvents (get_io_handle (), &n))
int ret = 0;
INPUT_RECORD inp[INREC_SIZE];
if (!PeekConsoleInputW (get_io_handle (), inp, INREC_SIZE, &n))
{
__seterrno ();
set_errno (EINVAL);
return -1;
}
*(int *) buf = (int) n;
while (n-- > 0)
if (inp[n].EventType == KEY_EVENT && inp[n].Event.KeyEvent.bKeyDown)
++ret;
*(int *) buf = ret;
return 0;
}
break;