From 7a27ef143966debae7bba5e880a31c0bb6908ddb Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 9 May 2023 15:36:28 -0400 Subject: [PATCH] generic/tty: Add the undocumented BeOS 'ichr' ioctl. This was used by the BeOS port of ncurses, as well as our own ncurses port until not too long before the alpha1 days, so we should keep it around for compatibility. Implementation copied directly from the "legacy" TTY driver. --- src/add-ons/kernel/generic/tty/tty.cpp | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/add-ons/kernel/generic/tty/tty.cpp b/src/add-ons/kernel/generic/tty/tty.cpp index 3425748cf0..fba586bb02 100644 --- a/src/add-ons/kernel/generic/tty/tty.cpp +++ b/src/add-ons/kernel/generic/tty/tty.cpp @@ -1680,6 +1680,39 @@ tty_control(tty_cookie* cookie, uint32 op, void* buffer, size_t length) return B_OK; } + case 'ichr': // BeOS (int*) (pre- select() support) + { + int wanted; + int toRead; + + // help identify apps using it + //dprintf("tty: warning: legacy BeOS opcode 'ichr'\n"); + + if (user_memcpy(&wanted, buffer, sizeof(int)) != B_OK) + return B_BAD_ADDRESS; + + // release the mutex and grab a read lock + locker.Unlock(); + ReaderLocker readLocker(cookie); + + bigtime_t timeout = wanted == 0 ? 0 : B_INFINITE_TIMEOUT; + + // TODO: If wanted is > the TTY buffer size, this loop cannot work + // correctly. Refactor the read code! + do { + status_t status = readLocker.AcquireReader(timeout, wanted); + if (status != B_OK) + return status; + + toRead = readLocker.AvailableBytes(); + } while (toRead < wanted); + + if (user_memcpy(buffer, &toRead, sizeof(int)) != B_OK) + return B_BAD_ADDRESS; + + return B_OK; + } + case FIONREAD: { int toRead = 0;