diff options
Diffstat (limited to 'termios')
-rw-r--r-- | termios/Makefile | 32 | ||||
-rw-r--r-- | termios/Versions | 7 | ||||
-rw-r--r-- | termios/baud.c | 56 | ||||
-rw-r--r-- | termios/cfsetbaud.c | 29 | ||||
-rw-r--r-- | termios/cfsetspeed.c | 142 | ||||
-rw-r--r-- | termios/isatty.c | 31 | ||||
-rw-r--r-- | termios/isatty_nostatus.c | 29 | ||||
-rw-r--r-- | termios/speed.c | 18 | ||||
-rw-r--r-- | termios/sys/ttychars.h | 4 | ||||
-rw-r--r-- | termios/tcsetattr.c | 5 | ||||
-rw-r--r-- | termios/termios.h | 20 |
11 files changed, 222 insertions, 151 deletions
diff --git a/termios/Makefile b/termios/Makefile index 0807542..1e23608 100644 --- a/termios/Makefile +++ b/termios/Makefile @@ -22,11 +22,33 @@ subdir := termios include ../Makeconfig -headers := termios.h bits/termios.h sys/ttydefaults.h sys/termios.h \ - sys/ttychars.h - -routines := speed cfsetspeed tcsetattr tcgetattr tcgetpgrp tcsetpgrp \ - tcdrain tcflow tcflush tcsendbrk cfmakeraw tcgetsid +headers := \ + bits/termios-baud.h \ + bits/termios.h \ + sys/termios.h \ + sys/ttychars.h \ + sys/ttydefaults.h \ + termios.h \ + # headers + +routines := \ + baud \ + cfmakeraw \ + cfsetbaud \ + cfsetspeed \ + isatty \ + isatty_nostatus \ + speed \ + tcdrain \ + tcflow \ + tcflush \ + tcgetattr \ + tcgetpgrp \ + tcgetsid \ + tcsendbrk \ + tcsetattr \ + tcsetpgrp \ + # routines include ../Rules diff --git a/termios/Versions b/termios/Versions index 711ed03..03e2063 100644 --- a/termios/Versions +++ b/termios/Versions @@ -3,6 +3,9 @@ libc { # c* cfgetispeed; cfgetospeed; cfmakeraw; cfsetispeed; cfsetospeed; cfsetspeed; + # i* + isatty; + # t* tcdrain; tcflow; tcflush; tcgetattr; tcgetpgrp; tcsendbreak; tcsetattr; tcsetpgrp; @@ -11,4 +14,8 @@ libc { # t* tcgetsid; } + GLIBC_2.42 { + # cf*baud + cfgetibaud; cfgetobaud; cfsetibaud; cfsetobaud; cfsetbaud; + } } diff --git a/termios/baud.c b/termios/baud.c new file mode 100644 index 0000000..27c06e9 --- /dev/null +++ b/termios/baud.c @@ -0,0 +1,56 @@ +/* `struct termios' speed frobnication functions, baud rate wrappers. + Any platform which doesn't have Bxxx == xxx for all baud rate + constants will need to override this file. + + Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <errno.h> +#include <termios.h> + +baud_t +__cfgetobaud (const struct termios *termios_p) +{ + return __cfgetospeed (termios_p); +} +libc_hidden_def (__cfgetobaud) +weak_alias (__cfgetobaud, cfgetobaud) + +baud_t +__cfgetibaud (const struct termios *termios_p) +{ + return __cfgetispeed (termios_p); +} +libc_hidden_def (__cfgetibaud) +weak_alias (__cfgetibaud, cfgetibaud) + +int +__cfsetobaud (struct termios *termios_p, baud_t baud) +{ + return __cfsetospeed (termios_p, baud); +} +libc_hidden_def (__cfsetobaud) +weak_alias (__cfsetobaud, cfsetobaud) + +int +__cfsetibaud (struct termios *termios_p, baud_t baud) +{ + return __cfsetispeed (termios_p, baud); +} +libc_hidden_def (__cfsetibaud) +weak_alias (__cfsetibaud, cfsetibaud) diff --git a/termios/cfsetbaud.c b/termios/cfsetbaud.c new file mode 100644 index 0000000..b76b51e --- /dev/null +++ b/termios/cfsetbaud.c @@ -0,0 +1,29 @@ +/* Copyright (C) 1992-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <termios.h> +#include <errno.h> +#include <stddef.h> + +/* Set both the input and output baud rates stored in *TERMIOS_P to BAUD. */ +int +__cfsetbaud (struct termios *termios_p, baud_t baud) +{ + return __cfsetspeed (termios_p, baud); +} +libc_hidden_def (__cfsetbaud) +weak_alias (__cfsetbaud, cfsetbaud) diff --git a/termios/cfsetspeed.c b/termios/cfsetspeed.c index 053e394..a68e63a 100644 --- a/termios/cfsetspeed.c +++ b/termios/cfsetspeed.c @@ -19,143 +19,17 @@ #include <errno.h> #include <stddef.h> -struct speed_struct -{ - speed_t value; - speed_t internal; -}; - -static const struct speed_struct speeds[] = - { -#ifdef B0 - { 0, B0 }, -#endif -#ifdef B50 - { 50, B50 }, -#endif -#ifdef B75 - { 75, B75 }, -#endif -#ifdef B110 - { 110, B110 }, -#endif -#ifdef B134 - { 134, B134 }, -#endif -#ifdef B150 - { 150, B150 }, -#endif -#ifdef B200 - { 200, B200 }, -#endif -#ifdef B300 - { 300, B300 }, -#endif -#ifdef B600 - { 600, B600 }, -#endif -#ifdef B1200 - { 1200, B1200 }, -#endif -#ifdef B1200 - { 1200, B1200 }, -#endif -#ifdef B1800 - { 1800, B1800 }, -#endif -#ifdef B2400 - { 2400, B2400 }, -#endif -#ifdef B4800 - { 4800, B4800 }, -#endif -#ifdef B9600 - { 9600, B9600 }, -#endif -#ifdef B19200 - { 19200, B19200 }, -#endif -#ifdef B38400 - { 38400, B38400 }, -#endif -#ifdef B57600 - { 57600, B57600 }, -#endif -#ifdef B76800 - { 76800, B76800 }, -#endif -#ifdef B115200 - { 115200, B115200 }, -#endif -#ifdef B153600 - { 153600, B153600 }, -#endif -#ifdef B230400 - { 230400, B230400 }, -#endif -#ifdef B307200 - { 307200, B307200 }, -#endif -#ifdef B460800 - { 460800, B460800 }, -#endif -#ifdef B500000 - { 500000, B500000 }, -#endif -#ifdef B576000 - { 576000, B576000 }, -#endif -#ifdef B921600 - { 921600, B921600 }, -#endif -#ifdef B1000000 - { 1000000, B1000000 }, -#endif -#ifdef B1152000 - { 1152000, B1152000 }, -#endif -#ifdef B1500000 - { 1500000, B1500000 }, -#endif -#ifdef B2000000 - { 2000000, B2000000 }, -#endif -#ifdef B2500000 - { 2500000, B2500000 }, -#endif -#ifdef B3000000 - { 3000000, B3000000 }, -#endif -#ifdef B3500000 - { 3500000, B3500000 }, -#endif -#ifdef B4000000 - { 4000000, B4000000 }, -#endif - }; - - /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */ int -cfsetspeed (struct termios *termios_p, speed_t speed) +__cfsetspeed (struct termios *termios_p, speed_t speed) { - size_t cnt; - - for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt) - if (speed == speeds[cnt].internal) - { - cfsetispeed (termios_p, speed); - cfsetospeed (termios_p, speed); - return 0; - } - else if (speed == speeds[cnt].value) - { - cfsetispeed (termios_p, speeds[cnt].internal); - cfsetospeed (termios_p, speeds[cnt].internal); - return 0; - } + int rv; - __set_errno (EINVAL); + rv = __cfsetospeed (termios_p, speed); + if (rv) + return rv; - return -1; + return __cfsetispeed (termios_p, speed); } +libc_hidden_def (__cfsetspeed) +weak_alias (__cfsetspeed, cfsetspeed) diff --git a/termios/isatty.c b/termios/isatty.c new file mode 100644 index 0000000..3f3912d --- /dev/null +++ b/termios/isatty.c @@ -0,0 +1,31 @@ +/* Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <unistd.h> + +/* Return 1 if FD is a terminal, 0 if not. */ +int +__isatty (int fd) +{ + __set_errno (ENOSYS); + return -1; +} + +weak_alias (__isatty, isatty) + +stub_warning (isatty) diff --git a/termios/isatty_nostatus.c b/termios/isatty_nostatus.c new file mode 100644 index 0000000..e8ee796 --- /dev/null +++ b/termios/isatty_nostatus.c @@ -0,0 +1,29 @@ +/* Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <unistd.h> + +/* Return 1 if FD is a terminal, 0 if not, without changing errno */ +int +__isatty_nostatus (int fd) +{ + int save_errno = errno; + int res = __isatty (fd); + __set_errno (save_errno); + return res; +} diff --git a/termios/speed.c b/termios/speed.c index d65bf03..5030621 100644 --- a/termios/speed.c +++ b/termios/speed.c @@ -22,21 +22,25 @@ /* Return the output baud rate stored in *TERMIOS_P. */ speed_t -cfgetospeed (const struct termios *termios_p) +__cfgetospeed (const struct termios *termios_p) { return termios_p->__ospeed; } +libc_hidden_def (__cfgetospeed) +weak_alias (__cfgetospeed, cfgetospeed) /* Return the input baud rate stored in *TERMIOS_P. */ speed_t -cfgetispeed (const struct termios *termios_p) +__cfgetispeed (const struct termios *termios_p) { return termios_p->__ispeed; } +libc_hidden_def (__cfgetispeed) +weak_alias (__cfgetispeed, cfgetispeed) /* Set the output baud rate stored in *TERMIOS_P to SPEED. */ int -cfsetospeed (struct termios *termios_p, speed_t speed) +__cfsetospeed (struct termios *termios_p, speed_t speed) { if (termios_p == NULL) { @@ -47,11 +51,12 @@ cfsetospeed (struct termios *termios_p, speed_t speed) termios_p->__ospeed = speed; return 0; } -libc_hidden_def (cfsetospeed) +libc_hidden_def (__cfsetospeed) +weak_alias (__cfsetospeed, cfsetospeed) /* Set the input baud rate stored in *TERMIOS_P to SPEED. */ int -cfsetispeed (struct termios *termios_p, speed_t speed) +__cfsetispeed (struct termios *termios_p, speed_t speed) { if (termios_p == NULL) { @@ -62,4 +67,5 @@ cfsetispeed (struct termios *termios_p, speed_t speed) termios_p->__ispeed = speed; return 0; } -libc_hidden_def (cfsetispeed) +libc_hidden_def (__cfsetispeed) +weak_alias (__cfsetispeed, cfsetispeed) diff --git a/termios/sys/ttychars.h b/termios/sys/ttychars.h index 7043f60..eb1a815 100644 --- a/termios/sys/ttychars.h +++ b/termios/sys/ttychars.h @@ -54,8 +54,4 @@ struct ttychars { char tc_lnextc; /* literal next character */ }; -#ifdef __USE_OLD_TTY -#include <sys/ttydefaults.h> /* to pick up character defaults */ -#endif - #endif /* sys/ttychars.h */ diff --git a/termios/tcsetattr.c b/termios/tcsetattr.c index 30bc6d6..f0756be 100644 --- a/termios/tcsetattr.c +++ b/termios/tcsetattr.c @@ -23,7 +23,7 @@ static int bad_speed (speed_t speed); /* Set the state of FD to *TERMIOS_P. */ int -tcsetattr (int fd, int optional_actions, const struct termios *termios_p) +__tcsetattr (int fd, int optional_actions, const struct termios *termios_p) { if (fd < 0) { @@ -57,7 +57,8 @@ tcsetattr (int fd, int optional_actions, const struct termios *termios_p) __set_errno (ENOSYS); return -1; } -libc_hidden_def (tcsetattr) +libc_hidden_def (__tcsetattr) +weak_alias (__tcsetattr, tcsetattr) /* Strychnine checking. */ static int diff --git a/termios/termios.h b/termios/termios.h index 1755c50..91cbe87 100644 --- a/termios/termios.h +++ b/termios/termios.h @@ -61,6 +61,26 @@ extern int cfsetispeed (struct termios *__termios_p, speed_t __speed) __THROW; extern int cfsetspeed (struct termios *__termios_p, speed_t __speed) __THROW; #endif +#ifdef __USE_GNU +/* Interfaces that are explicitly numeric representations of baud rates */ +typedef speed_t baud_t; +#define BAUD_MAX SPEED_MAX + +/* Return the output baud rate stored in *TERMIOS_P. */ +extern baud_t cfgetobaud (const struct termios *__termios_p) __THROW; + +/* Return the input baud rate stored in *TERMIOS_P. */ +extern baud_t cfgetibaud (const struct termios *__termios_p) __THROW; + +/* Set the output baud rate stored in *TERMIOS_P to BAUD. */ +extern int cfsetobaud (struct termios *__termios_p, baud_t __baud) __THROW; + +/* Set the input baud rate stored in *TERMIOS_P to BAUD. */ +extern int cfsetibaud (struct termios *__termios_p, baud_t __baud) __THROW; + +/* Set both the input and output baud rates in *TERMIOS_OP to BAUD. */ +extern int cfsetbaud (struct termios *__termios_p, baud_t __baud) __THROW; +#endif /* Put the state of FD into *TERMIOS_P. */ extern int tcgetattr (int __fd, struct termios *__termios_p) __THROW; |