1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:57:44 +00:00

Add sys$ttyname_r and ttyname_r() + ttyname().

And print a greeting when sh starts up so we know which TTY we're on.
This commit is contained in:
Andreas Kling 2018-10-30 22:03:02 +01:00
parent 7a85384e47
commit 00c21d1590
12 changed files with 78 additions and 3 deletions

View file

@ -114,6 +114,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
return current->sys$set_mmap_name((void*)arg1, (size_t)arg2, (const char*)arg3);
case Syscall::PosixReadlink:
return current->sys$readlink((const char*)arg1, (char*)arg2, (size_t)arg3);
case Syscall::PosixTtynameR:
return current->sys$ttyname_r((int)arg1, (char*)arg2, (size_t)arg3);
default:
kprintf("int0x80: Unknown function %x requested {%x, %x, %x}\n", function, arg1, arg2, arg3);
break;

View file

@ -37,6 +37,7 @@ enum Function {
SetMmapName = 0x2005,
PosixReadlink = 0x2006,
PosixWrite = 0x2007,
PosixTtynameR = 0x2008,
};
void initialize();

View file

@ -13,6 +13,8 @@ public:
virtual String ttyName() const = 0;
protected:
virtual bool isTTY() const final { return true; }
TTY(unsigned major, unsigned minor);
void emit(byte);

View file

@ -741,7 +741,7 @@ ssize_t Task::sys$get_dir_entries(int fd, void* buffer, size_t size)
VALIDATE_USER_BUFFER(buffer, size);
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -1;
return -EBADF;
return handle->get_dir_entries((byte*)buffer, size);
}
@ -749,10 +749,25 @@ int Task::sys$seek(int fd, int offset)
{
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -1;
return -EBADF;
return handle->seek(offset, SEEK_SET);
}
int Task::sys$ttyname_r(int fd, char* buffer, size_t size)
{
VALIDATE_USER_BUFFER(buffer, size);
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -EBADF;
if (!handle->isTTY())
return -ENOTTY;
auto ttyName = handle->tty()->ttyName();
if (size < ttyName.length() + 1)
return -ERANGE;
strcpy(buffer, ttyName.characters());
return 0;
}
ssize_t Task::sys$write(int fd, const void* data, size_t size)
{
VALIDATE_USER_BUFFER(data, size);
@ -802,7 +817,7 @@ int Task::sys$close(int fd)
{
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -1;
return -EBADF;
// FIXME: Implement.
return 0;
}

View file

@ -111,6 +111,7 @@ public:
int sys$get_arguments(int* argc, char*** argv);
int sys$uname(utsname*);
int sys$readlink(const char*, char*, size_t);
int sys$ttyname_r(int fd, char*, size_t);
static void initialize();