1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

Add basic PTY support.

For now, there are four hard-coded PTYs: /dev/pt{m,s}[0123]
Use this in the Terminal to open a pty pair and spawn a shell.
This commit is contained in:
Andreas Kling 2019-01-15 06:30:19 +01:00
parent ecb4ab0943
commit 2f74c2f430
21 changed files with 287 additions and 10 deletions

42
Kernel/MasterPTY.cpp Normal file
View file

@ -0,0 +1,42 @@
#include "MasterPTY.h"
#include "SlavePTY.h"
MasterPTY::MasterPTY(unsigned index)
: CharacterDevice(10, index)
, m_index(index)
{
}
MasterPTY::~MasterPTY()
{
}
String MasterPTY::pts_name() const
{
dbgprintf("MasterPTY::pts_name requested for index %u!\n", m_index);
char buffer[32];
ksprintf(buffer, "/dev/pts%u", m_index);
return buffer;
}
ssize_t MasterPTY::read(byte* buffer, size_t size)
{
return m_buffer.read(buffer, size);
}
ssize_t MasterPTY::write(const byte* buffer, size_t size)
{
m_slave->on_master_write(buffer, size);
return size;
}
bool MasterPTY::has_data_available_for_reading(Process&) const
{
return !m_buffer.is_empty();
}
void MasterPTY::on_slave_write(const byte* data, size_t size)
{
m_buffer.write(data, size);
}