Cygwin: console: Fix ioctl() FIONREAD.
- ioctl() FIONREAD for console does not return correct value since
commit cfb517f39a
. This patch fixes
the issue.
This commit is contained in:
parent
fe86a2418d
commit
bb87c87f52
|
@ -1230,9 +1230,38 @@ fhandler_console::ioctl (unsigned int cmd, void *arg)
|
||||||
release_output_mutex ();
|
release_output_mutex ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (n-- > 0)
|
bool saw_eol = false;
|
||||||
if (inp[n].EventType == KEY_EVENT && inp[n].Event.KeyEvent.bKeyDown)
|
for (DWORD i=0; i<n; i++)
|
||||||
++ret;
|
if (inp[i].EventType == KEY_EVENT &&
|
||||||
|
inp[i].Event.KeyEvent.bKeyDown &&
|
||||||
|
inp[i].Event.KeyEvent.uChar.UnicodeChar)
|
||||||
|
{
|
||||||
|
WCHAR wc = inp[i].Event.KeyEvent.uChar.UnicodeChar;
|
||||||
|
char mbs[8];
|
||||||
|
int len = con.con_to_str (mbs, sizeof (mbs), wc);
|
||||||
|
if ((get_ttyp ()->ti.c_lflag & ICANON) &&
|
||||||
|
len == 1 && CCEQ (get_ttyp ()->ti.c_cc[VEOF], mbs[0]))
|
||||||
|
{
|
||||||
|
saw_eol = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret += len;
|
||||||
|
const char eols[] = {
|
||||||
|
'\n',
|
||||||
|
'\r',
|
||||||
|
(char) get_ttyp ()->ti.c_cc[VEOL],
|
||||||
|
(char) get_ttyp ()->ti.c_cc[VEOL2]
|
||||||
|
};
|
||||||
|
if ((get_ttyp ()->ti.c_lflag & ICANON) &&
|
||||||
|
len == 1 && memchr (eols, mbs[0], sizeof (eols)))
|
||||||
|
{
|
||||||
|
saw_eol = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((get_ttyp ()->ti.c_lflag & ICANON) && !saw_eol)
|
||||||
|
*(int *) arg = 0;
|
||||||
|
else
|
||||||
*(int *) arg = ret;
|
*(int *) arg = ret;
|
||||||
release_output_mutex ();
|
release_output_mutex ();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue