diff options
Diffstat (limited to 'Kernel/TTY')
-rw-r--r-- | Kernel/TTY/SlavePTY.cpp | 6 | ||||
-rw-r--r-- | Kernel/TTY/TTY.cpp | 24 | ||||
-rw-r--r-- | Kernel/TTY/VirtualConsole.cpp | 8 |
3 files changed, 18 insertions, 20 deletions
diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index a53a378846..65bcd89a85 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -46,12 +46,12 @@ void SlavePTY::echo(u8 ch) void SlavePTY::on_master_write(const UserOrKernelBuffer& buffer, ssize_t size) { - ssize_t nread = buffer.read_buffered<128>(size, [&](const u8* data, size_t data_size) { + auto result = buffer.read_buffered<128>(size, [&](u8 const* data, size_t data_size) { for (size_t i = 0; i < data_size; ++i) emit(data[i], false); - return (ssize_t)data_size; + return data_size; }); - if (nread > 0) + if (!result.is_error()) evaluate_block_conditions(); } diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index 020150c86f..516b255e4d 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -43,10 +43,10 @@ KResultOr<size_t> TTY::read(FileDescription&, u64, UserOrKernelBuffer& buffer, s if (m_input_buffer.size() < static_cast<size_t>(size)) size = m_input_buffer.size(); - ssize_t nwritten; + KResultOr<size_t> result = 0; bool need_evaluate_block_conditions = false; if (in_canonical_mode()) { - nwritten = buffer.write_buffered<512>(size, [&](u8* data, size_t data_size) { + result = buffer.write_buffered<512>(size, [&](u8* data, size_t data_size) { size_t i = 0; for (; i < data_size; i++) { u8 ch = m_input_buffer.dequeue(); @@ -64,10 +64,10 @@ KResultOr<size_t> TTY::read(FileDescription&, u64, UserOrKernelBuffer& buffer, s } data[i] = ch; } - return (ssize_t)i; + return i; }); } else { - nwritten = buffer.write_buffered<512>(size, [&](u8* data, size_t data_size) { + result = buffer.write_buffered<512>(size, [&](u8* data, size_t data_size) { for (size_t i = 0; i < data_size; i++) { auto ch = m_input_buffer.dequeue(); if (ch == '\r' && m_termios.c_iflag & ICRNL) @@ -76,14 +76,12 @@ KResultOr<size_t> TTY::read(FileDescription&, u64, UserOrKernelBuffer& buffer, s ch = '\r'; data[i] = ch; } - return (ssize_t)data_size; + return data_size; }); } - if (nwritten < 0) - return KResult((ErrnoCode)-nwritten); - if (nwritten > 0 || need_evaluate_block_conditions) + if ((!result.is_error() && result.value() > 0) || need_evaluate_block_conditions) evaluate_block_conditions(); - return (size_t)nwritten; + return result; } KResultOr<size_t> TTY::write(FileDescription&, u64, const UserOrKernelBuffer& buffer, size_t size) @@ -93,8 +91,8 @@ KResultOr<size_t> TTY::write(FileDescription&, u64, const UserOrKernelBuffer& bu return EINTR; } - const size_t num_chars = 256; - ssize_t nread = buffer.read_buffered<num_chars>((size_t)size, [&](const u8* data, size_t buffer_bytes) { + constexpr size_t num_chars = 256; + return buffer.read_buffered<num_chars>(size, [&](u8 const* data, size_t buffer_bytes) { u8 modified_data[num_chars * 2]; size_t extra_chars = 0; for (size_t i = 0; i < buffer_bytes; ++i) { @@ -106,10 +104,8 @@ KResultOr<size_t> TTY::write(FileDescription&, u64, const UserOrKernelBuffer& bu modified_data[i + extra_chars] = ch; } on_tty_write(UserOrKernelBuffer::for_kernel_buffer(modified_data), buffer_bytes + extra_chars); - return (ssize_t)buffer_bytes; + return buffer_bytes; }); - - return nread; } bool TTY::can_read(const FileDescription&, size_t) const diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index e33fdbe7c0..5ac13edee4 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -226,14 +226,16 @@ void VirtualConsole::on_key_pressed(KeyEvent event) ssize_t VirtualConsole::on_tty_write(const UserOrKernelBuffer& data, ssize_t size) { ScopedSpinLock lock(s_lock); - ssize_t nread = data.read_buffered<512>((size_t)size, [&](const u8* buffer, size_t buffer_bytes) { + auto result = data.read_buffered<512>((size_t)size, [&](u8 const* buffer, size_t buffer_bytes) { for (size_t i = 0; i < buffer_bytes; ++i) m_terminal.on_input(buffer[i]); - return (ssize_t)buffer_bytes; + return buffer_bytes; }); if (m_active) flush_dirty_lines(); - return nread; + if (result.is_error()) + return result.error(); + return (ssize_t)result.value(); } void VirtualConsole::set_vga_start_row(u16 row) |