diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/termios | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/termios')
| -rw-r--r-- | lib/libc/termios/cfgetispeed.c | 6 | ||||
| -rw-r--r-- | lib/libc/termios/cfgetospeed.c | 6 | ||||
| -rw-r--r-- | lib/libc/termios/cfsetispeed.c | 14 | ||||
| -rw-r--r-- | lib/libc/termios/cfsetospeed.c | 13 | ||||
| -rw-r--r-- | lib/libc/termios/tcdrain.c | 7 | ||||
| -rw-r--r-- | lib/libc/termios/tcflow.c | 7 | ||||
| -rw-r--r-- | lib/libc/termios/tcflush.c | 8 | ||||
| -rw-r--r-- | lib/libc/termios/tcgetattr.c | 9 | ||||
| -rw-r--r-- | lib/libc/termios/tcgetsid.c | 13 | ||||
| -rw-r--r-- | lib/libc/termios/tcgetwinsize.c | 23 | ||||
| -rw-r--r-- | lib/libc/termios/tcsendbreak.c | 11 | ||||
| -rw-r--r-- | lib/libc/termios/tcsetattr.c | 14 | ||||
| -rw-r--r-- | lib/libc/termios/tcsetwinsize.c | 8 |
13 files changed, 139 insertions, 0 deletions
diff --git a/lib/libc/termios/cfgetispeed.c b/lib/libc/termios/cfgetispeed.c new file mode 100644 index 00000000..f06ec65e --- /dev/null +++ b/lib/libc/termios/cfgetispeed.c @@ -0,0 +1,6 @@ +#include <asm-generic/termbits.h> + +speed_t cfgetispeed(const struct termios *termios_p) +{ + return (termios_p->c_cflag & CIBAUD) / (CIBAUD / CBAUD); +} diff --git a/lib/libc/termios/cfgetospeed.c b/lib/libc/termios/cfgetospeed.c new file mode 100644 index 00000000..e36befc3 --- /dev/null +++ b/lib/libc/termios/cfgetospeed.c @@ -0,0 +1,6 @@ +#include <asm-generic/termbits.h> + +speed_t cfgetospeed(const struct termios *termios_p) +{ + return termios_p->c_cflag & CBAUD; +} diff --git a/lib/libc/termios/cfsetispeed.c b/lib/libc/termios/cfsetispeed.c new file mode 100644 index 00000000..b990d598 --- /dev/null +++ b/lib/libc/termios/cfsetispeed.c @@ -0,0 +1,14 @@ +#include <errno.h> +#include <asm-generic/termbits.h> + +int cfsetispeed(struct termios *termios_p, speed_t speed) +{ + if (speed & ~CBAUD) { + errno = EINVAL; + return -1; + } + + termios_p->c_cflag &= ~CIBAUD; + termios_p->c_cflag |= speed * (CIBAUD / CBAUD); + return 0; +} diff --git a/lib/libc/termios/cfsetospeed.c b/lib/libc/termios/cfsetospeed.c new file mode 100644 index 00000000..3f46b5c4 --- /dev/null +++ b/lib/libc/termios/cfsetospeed.c @@ -0,0 +1,13 @@ +#include <errno.h> +#include <asm-generic/termbits.h> + +int cfsetospeed(struct termios *termios_p, speed_t speed) +{ + if (speed & ~CBAUD) { + errno = EINVAL; + return -1; + } + termios_p->c_cflag &= ~CBAUD; + termios_p->c_cflag |= speed; + return 0; +} diff --git a/lib/libc/termios/tcdrain.c b/lib/libc/termios/tcdrain.c new file mode 100644 index 00000000..9eefedf2 --- /dev/null +++ b/lib/libc/termios/tcdrain.c @@ -0,0 +1,7 @@ +#include <asm-generic/ioctls.h> +#include <syscall.h> + +int tcdrain(int fildes) +{ + return syscall(ioctl, fildes, TCSBRK, 1); +} diff --git a/lib/libc/termios/tcflow.c b/lib/libc/termios/tcflow.c new file mode 100644 index 00000000..a10455d1 --- /dev/null +++ b/lib/libc/termios/tcflow.c @@ -0,0 +1,7 @@ +#include <asm-generic/ioctls.h> +#include <syscall.h> + +int tcflow(int fildes, int action) +{ + return syscall(ioctl, fildes, TCXONC, action); +} diff --git a/lib/libc/termios/tcflush.c b/lib/libc/termios/tcflush.c new file mode 100644 index 00000000..b37b218d --- /dev/null +++ b/lib/libc/termios/tcflush.c @@ -0,0 +1,8 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> + +int tcflush(int fildes, int queue_selector) +{ + return syscall(ioctl, fildes, TCFLSH, queue_selector); +} diff --git a/lib/libc/termios/tcgetattr.c b/lib/libc/termios/tcgetattr.c new file mode 100644 index 00000000..a52eeedf --- /dev/null +++ b/lib/libc/termios/tcgetattr.c @@ -0,0 +1,9 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> + +int tcgetattr(int fildes, struct termios *termios_p) + +{ + return syscall(ioctl, fildes, TCGETS, termios_p); +} diff --git a/lib/libc/termios/tcgetsid.c b/lib/libc/termios/tcgetsid.c new file mode 100644 index 00000000..076cf360 --- /dev/null +++ b/lib/libc/termios/tcgetsid.c @@ -0,0 +1,13 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> + +pid_t tcgetsid(int fildes) +{ + pid_t sid = 0; + + if (syscall(ioctl, fildes, TIOCGSID, &sid) < 0) + return -1; + + return sid; +} diff --git a/lib/libc/termios/tcgetwinsize.c b/lib/libc/termios/tcgetwinsize.c new file mode 100644 index 00000000..2c7c5786 --- /dev/null +++ b/lib/libc/termios/tcgetwinsize.c @@ -0,0 +1,23 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> + +struct __winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +int tcgetwinsize(int fildes, struct winsize *winsize_p) +{ + long ret; + struct __winsize winsize = { 0 }; + + ret = syscall(ioctl, fildes, TIOCGWINSZ, &winsize); + + winsize_p->ws_row = winsize.ws_row; + winsize_p->ws_col = winsize.ws_col; + + return ret; +} diff --git a/lib/libc/termios/tcsendbreak.c b/lib/libc/termios/tcsendbreak.c new file mode 100644 index 00000000..a6ed420d --- /dev/null +++ b/lib/libc/termios/tcsendbreak.c @@ -0,0 +1,11 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> + +int tcsendbreak(int fildes, int duration) +{ + // IEEE Std 1003.1-2024 + // If duration is not 0, it shall send zero-valued + // bits for an implementation-defined period of time. + return syscall(ioctl, fildes, TCSBRK, 0); +} diff --git a/lib/libc/termios/tcsetattr.c b/lib/libc/termios/tcsetattr.c new file mode 100644 index 00000000..a76e77a5 --- /dev/null +++ b/lib/libc/termios/tcsetattr.c @@ -0,0 +1,14 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> +#include <errno.h> + +int tcsetattr(int fildes, int optional_actions, const struct termios *termios_p) +{ + if (optional_actions < 0 || optional_actions > 2) { + errno = EINVAL; + return -1; + } + + return syscall(ioctl, fildes, TCSETS + optional_actions, termios_p); +} diff --git a/lib/libc/termios/tcsetwinsize.c b/lib/libc/termios/tcsetwinsize.c new file mode 100644 index 00000000..10a705d0 --- /dev/null +++ b/lib/libc/termios/tcsetwinsize.c @@ -0,0 +1,8 @@ +#include <termios.h> +#include <syscall.h> +#include <asm-generic/ioctls.h> + +int tcsetwinsize(int fildes, const struct winsize *winsize_p) +{ + return syscall(ioctl, fildes, TIOCSWINSZ, winsize_p); +} |
