From patchwork Fri Jul 4 12:59:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 115655 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06C2B385141F for ; Fri, 4 Jul 2025 13:00:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06C2B385141F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RSc7Jj8N X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 5B2B138515D2 for ; Fri, 4 Jul 2025 12:59:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B2B138515D2 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5B2B138515D2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751633974; cv=none; b=XuVBNM2vHX1hOxSeYFqCLoJAsySPjPKMbS0EXoAdrYHP9gzETOIJ/zPiocm6q0oAnWhP7rn5CfVehDioUc4xl5h0ZOvNTWkYxk5dyi0h8ilwlHrlcWckHx6HZ7oGneB9NQX5DCtP/fj3RC+EniFriHDPqdsbb0EY6H3RJH937jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751633974; c=relaxed/simple; bh=PTyzaCzkchDWqcmijppdqBbcD2PiZD38wK+Hx1DlQPo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=euWe4cCI8WjzyeRMmqbc4xLR0W54AnbP6CIEXiD9PgABADYCjhGjCmLuQhEOV2+RL4+wOe/JGDlufzgxC592530ZA4XEZ34jri/mWEzvgmE7mspyWbn/sruZc9LKMtXs6K8zUxTkq3M2RpAwcSKrskLFlcMS1+m/ZqOvg4ovPXQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B2B138515D2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751633974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=VkHE+j8/X7zryPlDtKMS9xmuslLuX2c9WgPRwu955Vc=; b=RSc7Jj8NzvYimMgaGIh2+auLAiLksXd5RdBEnUQFyygrcYz+dRWdH4JMqtmS+R00QW1JUm +/6oyEIPHjoRzoXxWYieetkFL+0IYGlIkm5DXHmni+6jTh2p8Rqb4UD8DuX/DR/0MIVB+L aXl9j/yKtJLqggCLMtAhStGhTdd1ybE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-4day63-JP4O4S9FT-RldgA-1; Fri, 04 Jul 2025 08:59:30 -0400 X-MC-Unique: 4day63-JP4O4S9FT-RldgA-1 X-Mimecast-MFC-AGG-ID: 4day63-JP4O4S9FT-RldgA_1751633970 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AEDBF180029E; Fri, 4 Jul 2025 12:59:29 +0000 (UTC) Received: from fweimer-oldenburg.csb.redhat.com (unknown [10.2.16.11]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E80A5195E753; Fri, 4 Jul 2025 12:59:27 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , H. Peter Anvin (Intel) , Javier Martinez Canillas Subject: [PATCH] Linux: Define struct termios2 and its ioctls on all architectures Date: Fri, 04 Jul 2025 14:59:36 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BPJaFi1QJVHzqCepUdjSjtq4LBuJjI9claiEQD-0rDg_1751633970 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, PROLO_LEO1, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org 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. This introduces a new installed header, , based on the previous internal header . Only publicly visible parameters are included, the internals for defining old_termios_t are moved into . 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(-) base-commit: 1c5f2ae4f98eb02fabab9f7f2b22ef6d23e85edc 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 . +* On Linux, no longer defines the constants TCGETS, + TCSETS, TCSETSF, TSETSW are no longer defined. Applications should + use the high-level functions from , or include + 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 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 . */ -#ifndef TERMIOS_INTERNALS_H -# error " should only be included from " +#ifndef _TERMIOS_H +# error "Never include directly; use 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 +/* 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 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 . */ +#ifndef _TERMIOS_H +# error "Never include directly; use 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 #endif +#include + +#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 #include #include 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 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 . */ +#ifndef _TERMIOS_H +# error "Never include directly; use 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 + . */ + +#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 -/* 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 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 . */ -#ifndef TERMIOS_INTERNALS_H -# error " should only be included from " +#ifndef _TERMIOS_H +# error "Never include directly; use 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 @@ . */ #include +#include /* 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 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 . */ +#ifndef _TERMIOS_H +# error "Never include directly; use 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 + . */ + +#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 + . */ + +#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 #include -#include - -/* ---- 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 /* 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 /* ---- 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 . */ + +#include +#include + +#include +#include +#include + +#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