termios: New ioctl: TIOCOUTQ

Change-Id: I86f2a7b007137e22cf7d6fc8ad6675ff5de267d4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6386
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
This commit is contained in:
Trung Nguyen 2023-05-09 20:47:14 +10:00 committed by Jessica Hamilton
parent 568b8f9395
commit d97ad7c4dc
3 changed files with 22 additions and 0 deletions

View File

@ -188,6 +188,7 @@ struct termios {
#define TIOCMBIS (TCGETA + 22) /* set bits in line state */
#define TIOCMBIC (TCGETA + 23) /* clear bits in line state */
#define TIOCGSID (TCGETA + 24) /* get session leader process group ID */
#define TIOCOUTQ (TCGETA + 25) /* get output queue size */
/* Event codes. Returned from TCWAITEVENT */
#define EV_RING 0x0001

View File

@ -1830,6 +1830,26 @@ tty_control(tty_cookie* cookie, uint32 op, void* buffer, size_t length)
return B_OK;
}
case TIOCOUTQ:
{
int toWrite = 0;
// release the mutex and grab a write lock
locker.Unlock();
WriterLocker writeLocker(cookie);
status_t status = writeLocker.AcquireWriter(0, 1);
if (status == B_OK)
toWrite = line_buffer_readable(tty->input_buffer);
else if (status != B_WOULD_BLOCK)
return status;
if (user_memcpy(buffer, &toWrite, sizeof(int)) != B_OK)
return B_BAD_ADDRESS;
return B_OK;
}
case TCXONC: // Unix, but even Linux doesn't handle it
//dprintf("tty: unsupported TCXONC\n");
break;

View File

@ -136,6 +136,7 @@ static const ioctl_info kIOCtls[] = {
IOCTL_INFO_ENTRY(TIOCCBRK),
IOCTL_INFO_ENTRY(TIOCMBIS),
IOCTL_INFO_ENTRY(TIOCMBIC),
IOCTL_INFO_ENTRY(TIOCOUTQ),
// private termios
IOCTL_INFO_ENTRY(B_IOCTL_GET_TTY_INDEX),
IOCTL_INFO_ENTRY(B_IOCTL_GRANT_TTY),