mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 20:32:56 +03:00
Kernel+LibC: Tidy up sys$ttyname() and sys$ptsname()
- Remove goofy _r suffix from syscall names. - Don't take a signed buffer size. - Use Userspace<T>. - Make TTY::tty_name() return a String instead of a StringView.
This commit is contained in:
parent
cb1fcd3eaf
commit
58feebeed2
Notes:
sideshowbarker
2024-07-19 04:18:59 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/58feebeed28
@ -76,7 +76,7 @@ namespace Kernel {
|
||||
S(set_mmap_name) \
|
||||
S(readlink) \
|
||||
S(write) \
|
||||
S(ttyname_r) \
|
||||
S(ttyname) \
|
||||
S(stat) \
|
||||
S(getsid) \
|
||||
S(setsid) \
|
||||
@ -111,7 +111,7 @@ namespace Kernel {
|
||||
S(times) \
|
||||
S(utime) \
|
||||
S(sync) \
|
||||
S(ptsname_r) \
|
||||
S(ptsname) \
|
||||
S(select) \
|
||||
S(unlink) \
|
||||
S(poll) \
|
||||
|
@ -246,8 +246,8 @@ public:
|
||||
int sys$sethostname(const char*, ssize_t);
|
||||
int sys$uname(utsname*);
|
||||
int sys$readlink(const Syscall::SC_readlink_params*);
|
||||
int sys$ttyname_r(int fd, char*, ssize_t);
|
||||
int sys$ptsname_r(int fd, char*, ssize_t);
|
||||
int sys$ttyname(int fd, Userspace<char*>, size_t);
|
||||
int sys$ptsname(int fd, Userspace<char*>, size_t);
|
||||
pid_t sys$fork(RegisterState&);
|
||||
int sys$execve(const Syscall::SC_execve_params*);
|
||||
int sys$dup(int oldfd);
|
||||
|
@ -31,11 +31,9 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
|
||||
int Process::sys$ttyname(int fd, Userspace<char*> buffer, size_t size)
|
||||
{
|
||||
REQUIRE_PROMISE(tty);
|
||||
if (size < 0)
|
||||
return -EINVAL;
|
||||
if (!validate_write(buffer, size))
|
||||
return -EFAULT;
|
||||
auto description = file_description(fd);
|
||||
@ -43,18 +41,16 @@ int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
|
||||
return -EBADF;
|
||||
if (!description->is_tty())
|
||||
return -ENOTTY;
|
||||
String tty_name = description->tty()->tty_name();
|
||||
if ((size_t)size < tty_name.length() + 1)
|
||||
auto tty_name = description->tty()->tty_name();
|
||||
if (size < tty_name.length() + 1)
|
||||
return -ERANGE;
|
||||
copy_to_user(buffer, tty_name.characters(), tty_name.length() + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::sys$ptsname_r(int fd, char* buffer, ssize_t size)
|
||||
int Process::sys$ptsname(int fd, Userspace<char*> buffer, size_t size)
|
||||
{
|
||||
REQUIRE_PROMISE(tty);
|
||||
if (size < 0)
|
||||
return -EINVAL;
|
||||
if (!validate_write(buffer, size))
|
||||
return -EFAULT;
|
||||
auto description = file_description(fd);
|
||||
@ -64,7 +60,7 @@ int Process::sys$ptsname_r(int fd, char* buffer, ssize_t size)
|
||||
if (!master_pty)
|
||||
return -ENOTTY;
|
||||
auto pts_name = master_pty->pts_name();
|
||||
if ((size_t)size < pts_name.length() + 1)
|
||||
if (size < pts_name.length() + 1)
|
||||
return -ERANGE;
|
||||
copy_to_user(buffer, pts_name.characters(), pts_name.length() + 1);
|
||||
return 0;
|
||||
|
@ -54,7 +54,7 @@ SlavePTY::~SlavePTY()
|
||||
DevPtsFS::unregister_slave_pty(*this);
|
||||
}
|
||||
|
||||
StringView SlavePTY::tty_name() const
|
||||
String SlavePTY::tty_name() const
|
||||
{
|
||||
return m_tty_name;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
// ^TTY
|
||||
virtual StringView tty_name() const override;
|
||||
virtual String tty_name() const override;
|
||||
virtual ssize_t on_tty_write(const u8*, ssize_t) override;
|
||||
virtual void echo(u8) override;
|
||||
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override final;
|
||||
virtual String absolute_path(const FileDescription&) const override { return tty_name(); }
|
||||
|
||||
virtual StringView tty_name() const = 0;
|
||||
virtual String tty_name() const = 0;
|
||||
|
||||
unsigned short rows() const { return m_rows; }
|
||||
unsigned short columns() const { return m_columns; }
|
||||
|
@ -55,7 +55,7 @@ private:
|
||||
|
||||
// ^TTY
|
||||
virtual ssize_t on_tty_write(const u8*, ssize_t) override;
|
||||
virtual StringView tty_name() const override { return m_tty_name; }
|
||||
virtual String tty_name() const override { return m_tty_name; }
|
||||
virtual void echo(u8) override;
|
||||
|
||||
// ^TerminalClient
|
||||
|
@ -670,7 +670,7 @@ char* ptsname(int fd)
|
||||
|
||||
int ptsname_r(int fd, char* buffer, size_t size)
|
||||
{
|
||||
int rc = syscall(SC_ptsname_r, fd, buffer, size);
|
||||
int rc = syscall(SC_ptsname, fd, buffer, size);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ ssize_t write(int fd, const void* buf, size_t count)
|
||||
|
||||
int ttyname_r(int fd, char* buffer, size_t size)
|
||||
{
|
||||
int rc = syscall(SC_ttyname_r, fd, buffer, size);
|
||||
int rc = syscall(SC_ttyname, fd, buffer, size);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user