tty: add ttyname ioctl

This commit is contained in:
Matheus
2024-05-28 18:12:05 -03:00
parent 1dd262fcca
commit 35eca115f5
2 changed files with 29 additions and 2 deletions
+7
View File
@@ -295,6 +295,8 @@ static int poll(int minor, polldata_t *data, int events) {
#define TIOCSCTTY 0x540E #define TIOCSCTTY 0x540E
#define TIOCGPGRP 0x540F #define TIOCGPGRP 0x540F
#define TIOCSPGRP 0x5410 #define TIOCSPGRP 0x5410
#define TTY_IOCTL_NAME 0x771101141113l
#define TTY_NAME_MAX 32
int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) { int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) {
switch (req) { switch (req) {
@@ -350,6 +352,11 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) {
PROC_RELEASE(proc); PROC_RELEASE(proc);
return error; return error;
} }
case TTY_IOCTL_NAME: {
size_t len = min(strlen(tty->name) + 1, TTY_NAME_MAX);
memcpy(arg, tty->name, len);
break;
}
default: default:
return ENOTTY; return ENOTTY;
} }
+22 -2
View File
@@ -192,10 +192,10 @@ index 0000000..e5b087a
+ +
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
new file mode 100644 new file mode 100644
index 0000000..e94f84f index 0000000..0755fba
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -0,0 +1,694 @@ @@ -0,0 +1,714 @@
+#include <bits/ensure.h> +#include <bits/ensure.h>
+#include <mlibc/debug.hpp> +#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp> +#include <mlibc/all-sysdeps.hpp>
@@ -284,6 +284,26 @@ index 0000000..e94f84f
+ return ENOSYS; + return ENOSYS;
+ } + }
+ +
+ #ifndef MLIBC_BUILDING_RTLD
+ #define TTY_IOCTL_NAME 0x771101141113l
+ #define TTY_NAME_MAX 32
+ #define TTY_PREFIX "/dev/"
+
+
+ int sys_ttyname(int fd, char * buffer, size_t size) {
+ size_t prefixlen = strlen(TTY_PREFIX);
+ if (size < TTY_NAME_MAX + prefixlen) {
+ mlibc::panicLogger() << "ttyname size too small" << frg::endlog;
+ __builtin_unreachable();
+ }
+
+ strcpy(buffer, TTY_PREFIX);
+
+ int res;
+ return sys_ioctl(fd, TTY_IOCTL_NAME, (void *)(buffer + prefixlen), &res);
+ }
+ #endif
+
+ int sys_fsync(int fd) { + int sys_fsync(int fd) {
+ long ret; + long ret;
+ return syscall(SYSCALL_FSYNC, &ret, fd); + return syscall(SYSCALL_FSYNC, &ret, fd);