mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 19:32:06 -05:00
a9204510a4
Instead of checking it at every call site (to generate EBADF), we make file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>. This allows us to wrap all the calls in TRY(). :^) The only place that got a little bit messier from this is sys$mount(), and there's a whole bunch of things there in need of cleanup.
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/FileSystem/FileDescription.h>
|
|
#include <Kernel/Process.h>
|
|
#include <Kernel/TTY/MasterPTY.h>
|
|
#include <Kernel/TTY/TTY.h>
|
|
|
|
namespace Kernel {
|
|
|
|
KResultOr<FlatPtr> Process::sys$ttyname(int fd, Userspace<char*> buffer, size_t size)
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
|
REQUIRE_PROMISE(tty);
|
|
auto description = TRY(fds().file_description(fd));
|
|
if (!description->is_tty())
|
|
return ENOTTY;
|
|
auto tty_name = description->tty()->tty_name();
|
|
if (size < tty_name.length() + 1)
|
|
return ERANGE;
|
|
return copy_to_user(buffer, tty_name.characters(), tty_name.length() + 1);
|
|
}
|
|
|
|
KResultOr<FlatPtr> Process::sys$ptsname(int fd, Userspace<char*> buffer, size_t size)
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
|
REQUIRE_PROMISE(tty);
|
|
auto description = TRY(fds().file_description(fd));
|
|
auto* master_pty = description->master_pty();
|
|
if (!master_pty)
|
|
return ENOTTY;
|
|
auto pts_name = master_pty->pts_name();
|
|
if (size < pts_name.length() + 1)
|
|
return ERANGE;
|
|
return copy_to_user(buffer, pts_name.characters(), pts_name.length() + 1);
|
|
}
|
|
|
|
}
|