forked from Bananymous/banan-os
LibC/Kernel: Implement ttyname
This commit is contained in:
parent
ca774dfeb5
commit
e5bb843059
|
@ -168,6 +168,7 @@ namespace Kernel
|
|||
BAN::ErrorOr<long> sys_smo_delete(SharedMemoryObjectManager::Key);
|
||||
BAN::ErrorOr<long> sys_smo_map(SharedMemoryObjectManager::Key);
|
||||
|
||||
BAN::ErrorOr<long> sys_ttyname(int fildes, char* storage);
|
||||
BAN::ErrorOr<long> sys_isatty(int fildes);
|
||||
|
||||
BAN::ErrorOr<long> sys_tty_ctrl(int fildes, int command, int flags);
|
||||
|
|
|
@ -1497,6 +1497,20 @@ namespace Kernel
|
|||
return m_mapped_regions.back()->vaddr();
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_ttyname(int fildes, char* storage)
|
||||
{
|
||||
LockGuard _(m_process_lock);
|
||||
TRY(validate_pointer_access(storage, TTY_NAME_MAX));
|
||||
auto inode = TRY(m_open_file_descriptors.inode_of(fildes));
|
||||
if (!inode->is_tty())
|
||||
return BAN::Error::from_errno(ENOTTY);
|
||||
auto path = TRY(m_open_file_descriptors.path_of(fildes));
|
||||
ASSERT(path.size() < TTY_NAME_MAX);
|
||||
strncpy(storage, path.data(), path.size());
|
||||
storage[path.size()] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_isatty(int fildes)
|
||||
{
|
||||
LockGuard _(m_process_lock);
|
||||
|
|
|
@ -62,6 +62,7 @@ __BEGIN_DECLS
|
|||
#define PATH_MAX 256
|
||||
#define LOGIN_NAME_MAX 256
|
||||
#define HOST_NAME_MAX 255
|
||||
#define TTY_NAME_MAX PATH_MAX
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ __BEGIN_DECLS
|
|||
O(SYS_GETSOCKOPT, getsockopt) \
|
||||
O(SYS_SETSOCKOPT, setsockopt) \
|
||||
O(SYS_REALPATH, realpath) \
|
||||
O(SYS_TTYNAME, ttyname) \
|
||||
|
||||
enum Syscall
|
||||
{
|
||||
|
|
|
@ -488,3 +488,11 @@ char* getlogin(void)
|
|||
endpwent();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char* ttyname(int fildes)
|
||||
{
|
||||
static char storage[_POSIX_TTY_NAME_MAX];
|
||||
if (syscall(SYS_TTYNAME, fildes, storage) == -1)
|
||||
return nullptr;
|
||||
return storage;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue