1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +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

@ -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;
}