[PATCH] Linux: Define struct termios2 and its ioctls on all architectures

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Fri Jul 4 13:16:42 GMT 2025



On 04/07/25 09:59, Florian Weimer wrote:
> Do not define the legacy ioctls that do not work with glibc's
> definition of struct termios.  With the changes here, the termios2
> ioctls should work on all architectures (unless the kernel is too
> old) if that's what applications need.
> 

Is this really a good move to export what was intended to be a powerpc
specific quick as de-facto interface? My understanding it glibc should
in fact hide the internal details of the kernel interface.

And what kind of issues is this trying to fix here? I know we had
some downstream build issues due the removal of old termios.h header,
but it is not clear why exporting termios2 will change.

> This introduces a new installed header, <bits/termios-arch.h>, based
> on the previous internal header <termios_arch.h>.  Only publicly
> visible parameters are included, the internals for defining
> old_termios_t are moved into <termios-old.h>.
> 
> Tested on i686-linux-gnu, powerpc64le-linux-gnu, x86_64-linux-gnu.
> Built with build-many-glibcs.py.
> 
> ---
>  NEWS                                               |  6 +++
>  sysdeps/unix/sysv/linux/Makefile                   |  2 +
>  sysdeps/unix/sysv/linux/alpha/bits/ioctls.h        | 10 ++--
>  .../alpha/{termios_arch.h => bits/termios-arch.h}  |  5 +-
>  sysdeps/unix/sysv/linux/bits/ioctls.h              |  9 ++++
>  .../linux/{termios_arch.h => bits/termios-arch.h}  |  6 ++-
>  sysdeps/unix/sysv/linux/bits/termios.h             | 21 ++++++++
>  sysdeps/unix/sysv/linux/hppa/bits/ioctls.h         | 10 ++--
>  .../mips/{termios_arch.h => bits/termios-arch.h}   | 17 ++-----
>  sysdeps/unix/sysv/linux/mips/termios-old.h         | 29 +++++++++++
>  sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h      | 23 +++++----
>  .../{termios_arch.h => bits/termios-arch.h}        |  5 +-
>  sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h   |  3 ++
>  sysdeps/unix/sysv/linux/sparc/bits/ioctls.h        | 10 ++--
>  .../sparc/{termios_arch.h => bits/termios-arch.h}  | 17 ++-----
>  sysdeps/unix/sysv/linux/sparc/termios-old.h        | 29 +++++++++++
>  sysdeps/unix/sysv/linux/termios-old.h              | 21 ++++++++
>  sysdeps/unix/sysv/linux/termios_internals.h        | 32 +-----------
>  sysdeps/unix/sysv/linux/tst-termios-linux-ioctl.c  | 58 ++++++++++++++++++++++
>  19 files changed, 228 insertions(+), 85 deletions(-)
> 
> diff --git a/NEWS b/NEWS
> index cc668344c1..f686cb32a9 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -37,6 +37,12 @@ Deprecated and removed features, and other changes affecting compatibility:
>    obsolete since the very first version of POSIX.1 in 1988, replaced
>    with <termios.h>.
>  
> +* On Linux, <sys/ioctl.h> no longer defines the constants TCGETS,
> +  TCSETS, TCSETSF, TSETSW are no longer defined.  Applications should

This sentence sounds strange, maybe cut the final 'are no longer defined'. 

> +  use the high-level functions from <termios.h>, or include <termios.h>

Also, wouldn't include termios.h add the high-level functions? This
sounds redudant.

> +  for a definition of struct termios2, and the ioctls TCGETS2, TCSETS2,
> +  TCSETSF2, TSETSW2.
> +
>  Changes to build and runtime requirements:
>  
>  * GCC 12.1 or later is now required to build the GNU C Library.
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index c47cbdf428..1c9c8d69ab 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -414,6 +414,7 @@ endif # $(subdir) == misc
>  
>  ifeq ($(subdir),termios)
>  sysdep_headers += \
> +  bits/termios-arch.h \
>    bits/termios-c_cc.h \
>    bits/termios-c_cflag.h \
>    bits/termios-c_iflag.h \
> @@ -427,6 +428,7 @@ sysdep_headers += \
>  
>  tests += \
>    tst-termios-linux \
> +  tst-termios-linux-ioctl \
>    # tests
>  endif
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h b/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
> index 77dc0c1c44..a6989b1fd6 100644
> --- a/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
> +++ b/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
> @@ -28,9 +28,11 @@
>  #undef  TCSETS
>  #undef  TCSETSW
>  #undef  TCSETSF
> -#define TCGETS	_IOR ('t', 19, char[44])
> -#define TCSETS	_IOW ('t', 20, char[44])
> -#define TCSETSW	_IOW ('t', 21, char[44])
> -#define TCSETSF	_IOW ('t', 22, char[44])
> +#ifdef _LIBC
> +# define TCGETS _IOR ('t', 19, char[44])
> +# define TCSETS _IOW ('t', 20, char[44])
> +# define TCSETSW _IOW ('t', 21, char[44])
> +# define TCSETSF _IOW ('t', 22, char[44])
> +#endif
>  
>  #include <linux/sockios.h>
> diff --git a/sysdeps/unix/sysv/linux/alpha/termios_arch.h b/sysdeps/unix/sysv/linux/alpha/bits/termios-arch.h
> similarity index 86%
> rename from sysdeps/unix/sysv/linux/alpha/termios_arch.h
> rename to sysdeps/unix/sysv/linux/alpha/bits/termios-arch.h
> index 20025f2549..097519d775 100644
> --- a/sysdeps/unix/sysv/linux/alpha/termios_arch.h
> +++ b/sysdeps/unix/sysv/linux/alpha/bits/termios-arch.h
> @@ -17,10 +17,9 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> -#ifndef TERMIOS_INTERNALS_H
> -# error "<termios_arch.h> should only be included from <termios_internals.h>"
> +#ifndef _TERMIOS_H
> +# error "Never include <bits/termios-arch.h> directly; use <termios.h> instead."
>  #endif
>  
>  #define _TERMIOS2_NCCS 19
>  #define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 1
> -#define _HAVE_STRUCT_OLD_TERMIOS 0
> diff --git a/sysdeps/unix/sysv/linux/bits/ioctls.h b/sysdeps/unix/sysv/linux/bits/ioctls.h
> index 1ddcd4f45a..dc95fad4b7 100644
> --- a/sysdeps/unix/sysv/linux/bits/ioctls.h
> +++ b/sysdeps/unix/sysv/linux/bits/ioctls.h
> @@ -22,4 +22,13 @@
>  /* Use the definitions from the kernel header files.  */
>  #include <asm/ioctls.h>
>  
> +/* This is necessary because the glibc definition of struct termios is
> +   different from the UAPI version, so these ioctls do not work.  */
> +#ifndef _LIBC
> +# undef TCGETS
> +# undef TCSETS
> +# undef TCSETSW
> +# undef TCSETSF
> +#endif
> +
>  #include <linux/sockios.h>
> diff --git a/sysdeps/unix/sysv/linux/termios_arch.h b/sysdeps/unix/sysv/linux/bits/termios-arch.h
> similarity index 89%
> rename from sysdeps/unix/sysv/linux/termios_arch.h
> rename to sysdeps/unix/sysv/linux/bits/termios-arch.h
> index 8dbf420c28..0b8b475595 100644
> --- a/sysdeps/unix/sysv/linux/termios_arch.h
> +++ b/sysdeps/unix/sysv/linux/bits/termios-arch.h
> @@ -17,7 +17,9 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> +#ifndef _TERMIOS_H
> +# error "Never include <bits/termios-arch.h> directly; use <termios.h> instead."
> +#endif
> +
>  #define _TERMIOS2_NCCS 19
>  #define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 0
> -
> -#define _HAVE_STRUCT_OLD_TERMIOS 0
> diff --git a/sysdeps/unix/sysv/linux/bits/termios.h b/sysdeps/unix/sysv/linux/bits/termios.h
> index 20746a0727..ab302e93ec 100644
> --- a/sysdeps/unix/sysv/linux/bits/termios.h
> +++ b/sysdeps/unix/sysv/linux/bits/termios.h
> @@ -28,6 +28,27 @@ typedef unsigned int	tcflag_t;
>  # include <bits/termios-struct.h>
>  #endif
>  
> +#include <bits/termios-arch.h>
> +
> +#ifdef __USE_MISC
> +struct termios2
> +{
> +  tcflag_t c_iflag;		/* input mode flags */
> +  tcflag_t c_oflag;		/* output mode flags */
> +  tcflag_t c_cflag;		/* control mode flags */
> +  tcflag_t c_lflag;		/* local mode flags */
> +# if _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE
> +  cc_t c_cc[_TERMIOS2_NCCS];	/* control characters */
> +  cc_t c_line;			/* line discipline */
> +# else
> +  cc_t c_line;			/* line discipline */
> +  cc_t c_cc[_TERMIOS2_NCCS];	/* control characters */
> +# endif
> +  speed_t c_ispeed;		/* input speed */
> +  speed_t c_ospeed;		/* output speed */
> +};
> +#endif
> +
>  #include <bits/termios-c_cc.h>
>  #include <bits/termios-c_iflag.h>
>  #include <bits/termios-c_oflag.h>
> diff --git a/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h b/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h
> index 6563be8030..292fdb6b4e 100644
> --- a/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h
> +++ b/sysdeps/unix/sysv/linux/hppa/bits/ioctls.h
> @@ -28,9 +28,11 @@
>  #undef  TCSETS
>  #undef  TCSETSW
>  #undef  TCSETSF
> -#define TCGETS	_IOR ('T', 16, char[36])
> -#define TCSETS	_IOW ('T', 17, char[36])
> -#define TCSETSW	_IOW ('T', 18, char[36])
> -#define TCSETSF	_IOW ('T', 19, char[36])
> +#ifdef _LIBC
> +# define TCGETS _IOR ('T', 16, char[36])
> +# define TCSETS _IOW ('T', 17, char[36])
> +# define TCSETSW _IOW ('T', 18, char[36])
> +# define TCSETSF _IOW ('T', 19, char[36])
> +#endif
>  
>  #include <linux/sockios.h>
> diff --git a/sysdeps/unix/sysv/linux/mips/termios_arch.h b/sysdeps/unix/sysv/linux/mips/bits/termios-arch.h
> similarity index 72%
> rename from sysdeps/unix/sysv/linux/mips/termios_arch.h
> rename to sysdeps/unix/sysv/linux/mips/bits/termios-arch.h
> index 392d9aa792..840236d11e 100644
> --- a/sysdeps/unix/sysv/linux/mips/termios_arch.h
> +++ b/sysdeps/unix/sysv/linux/mips/bits/termios-arch.h
> @@ -17,18 +17,9 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> +#ifndef _TERMIOS_H
> +# error "Never include <bits/termios-arch.h> directly; use <termios.h> instead."
> +#endif
> +
>  #define _TERMIOS2_NCCS 23
>  #define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 0
> -
> -#define _HAVE_STRUCT_OLD_TERMIOS 1
> -
> -#define OLD_NCCS 32
> -struct old_termios
> -{
> -  tcflag_t c_iflag;		/* input mode flags */
> -  tcflag_t c_oflag;		/* output mode flags */
> -  tcflag_t c_cflag;		/* control mode flags */
> -  tcflag_t c_lflag;		/* local mode flags */
> -  cc_t c_line;			/* line discipline */
> -  cc_t c_cc[OLD_NCCS];		/* control characters */
> -};
> diff --git a/sysdeps/unix/sysv/linux/mips/termios-old.h b/sysdeps/unix/sysv/linux/mips/termios-old.h
> new file mode 100644
> index 0000000000..45720f8352
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/mips/termios-old.h
> @@ -0,0 +1,29 @@
> +/* Old termios structure.  MIPS version.
> +   Copyright (C) 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/>.  */
> +
> +#define _HAVE_STRUCT_OLD_TERMIOS 1
> +#define OLD_NCCS 32
> +typedef struct
> +{
> +  tcflag_t c_iflag;            /* input mode flags */
> +  tcflag_t c_oflag;            /* output mode flags */
> +  tcflag_t c_cflag;            /* control mode flags */
> +  tcflag_t c_lflag;            /* local mode flags */
> +  cc_t c_line;                 /* line discipline */
> +  cc_t c_cc[OLD_NCCS];         /* control characters */
> +} old_termios_t;
> diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h b/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h
> index e1921dfb86..9e051eb82c 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h
> @@ -22,15 +22,20 @@
>  /* Use the definitions from the kernel header files.  */
>  #include <asm/ioctls.h>
>  
> -/* PowerPC quirk: on PowerPC only, ioctl() emulates the TCGETS/TCSETS*
> -   ioctls with tcgetattr/tcsetattr using the glibc struct termios.
> -   As struct termios2 is the same as the kernel struct termios on PowerPC,
> -   simply consider the kernel ones as the termios2 interface, even
> -   though the kernel doesn't call it that. */
> +/* This is necessary because the glibc definition of struct termios is
> +   different from the UAPI version, so these ioctls do not work.  */
> +#ifndef _LIBC
> +# undef TCGETS
> +# undef TCSETS
> +# undef TCSETSW
> +# undef TCSETSF
> +#endif
>  
> -#define TCGETS2	 _IOR ('t', 19, struct termios2)
> -#define TCSETS2	 _IOW ('t', 20, struct termios2)
> -#define TCSETSW2 _IOW ('t', 21, struct termios2)
> -#define TCSETSF2 _IOW ('t', 22, struct termios2)
> +/* On PowerPC, the kernel does not define these ioctls because UAPI
> +   struct termios is the same as UAPI struct termios2.  */
> +#define TCGETS2	 _IOR ('t', 19, char[44])
> +#define TCSETS2	 _IOW ('t', 20, char[44])
> +#define TCSETSW2 _IOW ('t', 21, char[44])
> +#define TCSETSF2 _IOW ('t', 22, char[44])
>  
>  #include <linux/sockios.h>
> diff --git a/sysdeps/unix/sysv/linux/powerpc/termios_arch.h b/sysdeps/unix/sysv/linux/powerpc/bits/termios-arch.h
> similarity index 86%
> rename from sysdeps/unix/sysv/linux/powerpc/termios_arch.h
> rename to sysdeps/unix/sysv/linux/powerpc/bits/termios-arch.h
> index 20025f2549..097519d775 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/termios_arch.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/bits/termios-arch.h
> @@ -17,10 +17,9 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> -#ifndef TERMIOS_INTERNALS_H
> -# error "<termios_arch.h> should only be included from <termios_internals.h>"
> +#ifndef _TERMIOS_H
> +# error "Never include <bits/termios-arch.h> directly; use <termios.h> instead."
>  #endif
>  
>  #define _TERMIOS2_NCCS 19
>  #define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 1
> -#define _HAVE_STRUCT_OLD_TERMIOS 0
> diff --git a/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h b/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h
> index 6c21357a9c..f98f430a8c 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/internal-ioctl.h
> @@ -17,12 +17,15 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <termios.h>
> +#include <assert.h>
>  
>  /* The user-visible size of struct termios has changed.  Catch ioctl calls
>     using the new-style struct termios, and translate them to old-style.  */
>  static inline bool
>  __ioctl_arch (int *r, int fd, unsigned long request, void *arg)
>  {
> +  static_assert (TCGETS != TCGETS2,
> +                 "emulation not possible due to match ioctl constants");
>    switch (request)
>      {
>      case TCGETS:
> diff --git a/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h b/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
> index 1a95466e8f..e238f82d03 100644
> --- a/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
> +++ b/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
> @@ -28,9 +28,11 @@
>  #undef  TCSETS
>  #undef  TCSETSW
>  #undef  TCSETSF
> -#define TCGETS	_IOR ('T', 8, char[36])
> -#define TCSETS	_IOW ('T', 9, char[36])
> -#define TCSETSW	_IOW ('T', 10, char[36])
> -#define TCSETSF	_IOW ('T', 11, char[36])
> +#ifdef _LIBC
> +# define TCGETS _IOR ('T', 8, char[36])
> +# define TCSETS _IOW ('T', 9, char[36])
> +# define TCSETSW _IOW ('T', 10, char[36])
> +# define TCSETSF _IOW ('T', 11, char[36])
> +#endif
>  
>  #include <linux/sockios.h>
> diff --git a/sysdeps/unix/sysv/linux/sparc/termios_arch.h b/sysdeps/unix/sysv/linux/sparc/bits/termios-arch.h
> similarity index 72%
> rename from sysdeps/unix/sysv/linux/sparc/termios_arch.h
> rename to sysdeps/unix/sysv/linux/sparc/bits/termios-arch.h
> index f3b3f656d1..093dadaa34 100644
> --- a/sysdeps/unix/sysv/linux/sparc/termios_arch.h
> +++ b/sysdeps/unix/sysv/linux/sparc/bits/termios-arch.h
> @@ -17,18 +17,9 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> +#ifndef _TERMIOS_H
> +# error "Never include <bits/termios-arch.h> directly; use <termios.h> instead."
> +#endif
> +
>  #define _TERMIOS2_NCCS 19
>  #define _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE 0
> -
> -#define _HAVE_STRUCT_OLD_TERMIOS 1
> -
> -#define OLD_NCCS 17
> -struct old_termios
> -{
> -  tcflag_t c_iflag;		/* input mode flags */
> -  tcflag_t c_oflag;		/* output mode flags */
> -  tcflag_t c_cflag;		/* control mode flags */
> -  tcflag_t c_lflag;		/* local mode flags */
> -  cc_t c_line;			/* line discipline */
> -  cc_t c_cc[OLD_NCCS];		/* control characters */
> -};
> diff --git a/sysdeps/unix/sysv/linux/sparc/termios-old.h b/sysdeps/unix/sysv/linux/sparc/termios-old.h
> new file mode 100644
> index 0000000000..d4f06ef000
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/sparc/termios-old.h
> @@ -0,0 +1,29 @@
> +/* Old termios structure.  SPARC version.
> +   Copyright (C) 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/>.  */
> +
> +#define _HAVE_STRUCT_OLD_TERMIOS 1
> +#define OLD_NCCS 17
> +typedef struct
> +{
> +  tcflag_t c_iflag;            /* input mode flags */
> +  tcflag_t c_oflag;            /* output mode flags */
> +  tcflag_t c_cflag;            /* control mode flags */
> +  tcflag_t c_lflag;            /* local mode flags */
> +  cc_t c_line;                 /* line discipline */
> +  cc_t c_cc[OLD_NCCS];         /* control characters */
> +} old_termios_t;
> diff --git a/sysdeps/unix/sysv/linux/termios-old.h b/sysdeps/unix/sysv/linux/termios-old.h
> new file mode 100644
> index 0000000000..494ecb3848
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/termios-old.h
> @@ -0,0 +1,21 @@
> +/* Old termios structure.  Generic version.
> +   Copyright (C) 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/>.  */
> +
> +#define _HAVE_STRUCT_OLD_TERMIOS 0
> +typedef struct termios old_termios_t;
> +#define OLD_NCCS NCCS
> diff --git a/sysdeps/unix/sysv/linux/termios_internals.h b/sysdeps/unix/sysv/linux/termios_internals.h
> index e8dbfe74de..3083f74ff9 100644
> --- a/sysdeps/unix/sysv/linux/termios_internals.h
> +++ b/sysdeps/unix/sysv/linux/termios_internals.h
> @@ -30,30 +30,7 @@
>  #include <sysdep.h>
>  #include <shlib-compat.h>
>  
> -#include <termios_arch.h>
> -
> -/* ---- Kernel interface definitions ---- */
> -
> -/* The the termios2 structure used in the kernel interfaces is not the
> -   same as the termios structure we use in the libc.  Therefore we
> -   must translate it here.  */
> -
> -struct termios2
> -{
> -  tcflag_t c_iflag;		/* input mode flags */
> -  tcflag_t c_oflag;		/* output mode flags */
> -  tcflag_t c_cflag;		/* control mode flags */
> -  tcflag_t c_lflag;		/* local mode flags */
> -#if _HAVE_TERMIOS2_C_CC_BEFORE_C_LINE
> -  cc_t c_cc[_TERMIOS2_NCCS];	/* control characters */
> -  cc_t c_line;			/* line discipline */
> -#else
> -  cc_t c_line;			/* line discipline */
> -  cc_t c_cc[_TERMIOS2_NCCS];	/* control characters */
> -#endif
> -  speed_t c_ispeed;		/* input speed */
> -  speed_t c_ospeed;		/* output speed */
> -};
> +#include <bits/termios-arch.h>
>  
>  /* Alpha got termios2 late, but TCGETS has exactly the same structure
>     format and function as TCGETS2. On all other platforms, the termios2
> @@ -91,12 +68,7 @@ struct termios2
>   * This only applies to SPARC and MIPS; for other architectures the
>   * new and old speed_t interfaces both use the same struct termios.
>   */
> -#if _HAVE_STRUCT_OLD_TERMIOS
> -typedef struct old_termios old_termios_t;
> -#else
> -# define OLD_NCCS NCCS
> -typedef struct termios old_termios_t;
> -#endif
> +#include <termios-old.h>
>  
>  /* ---- Internal function definitions ---- */
>  
> diff --git a/sysdeps/unix/sysv/linux/tst-termios-linux-ioctl.c b/sysdeps/unix/sysv/linux/tst-termios-linux-ioctl.c
> new file mode 100644
> index 0000000000..cc18d7000f
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-termios-linux-ioctl.c
> @@ -0,0 +1,58 @@
> +/* Test for termios ioctls.
> +   Copyright (C) 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; see the file COPYING.LIB.  If
> +   not, see <https://www.gnu.org/licenses/>.  */
> +
> +#include <sys/ioctl.h>
> +#include <termios.h>
> +
> +#include <support/check.h>
> +#include <support/tty.h>
> +#include <support/xunistd.h>
> +
> +#ifdef TCGETS
> +# error TCGETS defined
> +#endif
> +
> +#ifdef TCSETS
> +# error TCSETS defined
> +#endif
> +
> +#ifdef TCGETSW
> +# error TCGETSW defined
> +#endif
> +
> +#ifdef TCSETSF
> +# error TCSETSF defined
> +#endif
> +
> +static int
> +do_test (void)
> +{
> +  int ptmfd, ttyfd;
> +  support_openpty (&ptmfd, &ttyfd, NULL, NULL, NULL);
> +
> +  struct termios2 tios;
> +  TEST_COMPARE (ioctl (ttyfd, TCGETS2, &tios), 0);
> +  TEST_COMPARE (ioctl (ttyfd, TCSETS2, &tios), 0);
> +
> +  xclose (ttyfd);
> +  xclose (ptmfd);
> +
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>
> 
> base-commit: 1c5f2ae4f98eb02fabab9f7f2b22ef6d23e85edc
> 



More information about the Libc-alpha mailing list