From patchwork Sun Aug 27 23:43:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soumendra Ganguly X-Patchwork-Id: 74793 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 5C59A3858C52 for ; Sun, 27 Aug 2023 23:43:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C59A3858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693179811; bh=M5A2vpDbI8cZPGlh5wFFlPC4zq4HqtzZCIn6zFyrte8=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=a345d+o5mKgXljIQxjgfaaKWfDJkiSrwIwaGe+MAjS3z/HirumiEvvvZ5V5jRzwgg gPb6ZOifpSVYPaPnu6X2Gji5JF0ihTSrgv5Y2E11Wz/TcSbGiw3Q2KDvy4oeMl9jTM HldunuTfmKHbgEQAXZs6J0ET4qVjZj64H/o27vwk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 7E8C33858D28 for ; Sun, 27 Aug 2023 23:43:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E8C33858D28 Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-76f066e4fffso93997285a.2 for ; Sun, 27 Aug 2023 16:43:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693179781; x=1693784581; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=M5A2vpDbI8cZPGlh5wFFlPC4zq4HqtzZCIn6zFyrte8=; b=hxv7Aimh84+fjbQuCZQ8rh394RMrkfzZuTwqCKYrZVbPWVpMgUG339ho2JCTZyE/Fo quxgh+UTIPQS5eHplkLHG6WRPNYF7M8z9nvb7RMZiS34wgFvwglPBhFU5s/mMlMCd5BA TgLwYrxvYWhSDAsggY4CY77BSIGcVsNjiQSLyMCKSQUXQceU1MyMIyX57XRtv/k13cPq GbS2C0aalzpz0Di24U83Aj2paxm92urcTi8WaxYqlanRcyJoV85u/gqq1P7jmdC5tcq9 2qAbpnZ8+ENEUQn5x9R+eJXh//xfYnxKoH510OoAaEFFu4y2gfNlF8qh7T6bl2hb+E1r Crhg== X-Gm-Message-State: AOJu0YxHhznXOs5KosA5CHpXorVLxh16v7rE1nIPYvCXPAf+w+Uwaer8 hmTJ5+VtyjQAMaNJ509vuqJOilwVZWrGijY/Gyt1pRgl X-Google-Smtp-Source: AGHT+IETccS4pMhI0WTHaXXA4fklowUKJXLILb4iXxRDZ/VB2C8YlRylnaZ8X1fzUOGnL6bQDO7s7c9C3M6hRJjwHU0= X-Received: by 2002:a05:620a:b87:b0:76e:f320:9b4e with SMTP id k7-20020a05620a0b8700b0076ef3209b4emr9428919qkh.70.1693179781329; Sun, 27 Aug 2023 16:43:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:74d4:0:b0:79a:1d0b:c513 with HTTP; Sun, 27 Aug 2023 16:43:00 -0700 (PDT) Date: Sun, 27 Aug 2023 18:43:00 -0500 Message-ID: Subject: New functions tcgetwinsize and tcsetwinsize To: libc-alpha@sourceware.org Cc: fweimer@redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , X-Patchwork-Original-From: Soumendra Ganguly via Libc-alpha From: Soumendra Ganguly Reply-To: Soumendra Ganguly Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Good afternoon, I hope everyone is doing well. The attached patch is for adding the tcgetwinsize() and tcsetwinsize() functions that are expected to be a part of POSIX base specifications issue 8: https://www.austingroupbugs.net/view.php?id=1151#c3856. These functions get/set tty winsize respectively. In 2020, I had added these functions to FreeBSD's libc and to the termios module of cpython. They are also available in NetBSD and in musl libc. I had prepared a patch for glibc as well, but my university declined to release rights in 2020. Now I have graduated, and I am submitting an updated patch. Notes: 1. If this patch is accepted, then I will write manpages for the functions. 2. This is only implementing the functions on BSD and Linux, and the implementations are identical: the linux implementation simply includes the BSD implementation. Should the linux files include copyright messages as well? Please let me know if I should add it to other platforms, such as Hurd. 3. I have tested this on Linux: I wrote a custom test (attached file testwinsize.c) followed by "make check". The custom test is not a part of the patch. I have not tested it on the BSDs yet. I have also not tested the stub versions (termios/tcgetwinsize.c, termios/tcsetwinsize.c); should the stub versions have #include , libc_hidden_*, weak_alias, etc in them akin to the stub version of tcgetattr (termios/tcgetattr.c)? 4. In order to maintain current behavior of , I have added the #include within #if defined(TIOCGWINSZ) || defined(TIOCSWINSZ) guards in . However, the #include in is not within those guards. 5. The #include along with the tcgetwinsize() and tcsetwinsize() declarations in are currently within #ifdef __USE_GNU guards. Please let me know if that should be something else. When POSIX base specifications issue 8 is released, we will have to modify those guards and also update glibc/conform/data/termios.h-data. 6. I am still learning about the structure of the glibc source tree, and wrote this mainly based on grep, find, etc. Are changes to glibc/include/termios.h and/or glibc/posix/annexc.c necessary? Those files match when you grep for "tcgetattr". Thank you for your time. Sincerely, Soumendra From 84bb81d6ff8e441dfd45825742d557ae61065b46 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 27 Aug 2023 17:56:34 -0500 Subject: [PATCH] Add functions tcgetwinsize() and tcsetwinsize() which are set to appear in the upcoming POSIX Base Specifications, Issue 8. --- bits/ioctl-types.h | 13 ++----- bits/winsize.h | 36 +++++++++++++++++ sysdeps/unix/bsd/tcgetwinsize.c | 25 ++++++++++++ sysdeps/unix/bsd/tcsetwinsize.c | 25 ++++++++++++ sysdeps/unix/sysv/linux/bits/ioctl-types.h | 11 ++---- .../unix/sysv/linux/mips/bits/ioctl-types.h | 10 ++--- .../sysv/linux/powerpc/bits/ioctl-types.h | 11 ++---- sysdeps/unix/sysv/linux/tcgetwinsize.c | 1 + sysdeps/unix/sysv/linux/tcsetwinsize.c | 1 + termios/Makefile | 3 +- termios/Versions | 4 ++ termios/tcgetwinsize.c | 39 +++++++++++++++++++ termios/tcsetwinsize.c | 39 +++++++++++++++++++ termios/termios.h | 11 ++++++ 14 files changed, 195 insertions(+), 34 deletions(-) create mode 100644 bits/winsize.h create mode 100644 sysdeps/unix/bsd/tcgetwinsize.c create mode 100644 sysdeps/unix/bsd/tcsetwinsize.c create mode 100644 sysdeps/unix/sysv/linux/tcgetwinsize.c create mode 100644 sysdeps/unix/sysv/linux/tcsetwinsize.c create mode 100644 termios/tcgetwinsize.c create mode 100644 termios/tcsetwinsize.c diff --git a/bits/ioctl-types.h b/bits/ioctl-types.h index 961e5f8d3f..73308e819e 100644 --- a/bits/ioctl-types.h +++ b/bits/ioctl-types.h @@ -66,16 +66,9 @@ struct sgttyb _IOT (_IOTS (char), 4, _IOTS (short int), 1, 0, 0) #if defined TIOCGWINSZ || defined TIOCSWINSZ -/* Type of ARG for TIOCGWINSZ and TIOCSWINSZ requests. */ -struct winsize -{ - unsigned short int ws_row; /* Rows, in characters. */ - unsigned short int ws_col; /* Columns, in characters. */ - - /* These are not actually used. */ - unsigned short int ws_xpixel; /* Horizontal pixels. */ - unsigned short int ws_ypixel; /* Vertical pixels. */ -}; +/* Get the definition of 'struct winsize', which is the type of ARG for + TIOCGWINSZ and TIOCSWINSZ requests. */ +#include # define _IOT_winsize /* Hurd ioctl type field. */ \ _IOT (_IOTS (unsigned short int), 4, 0, 0, 0, 0) diff --git a/bits/winsize.h b/bits/winsize.h new file mode 100644 index 0000000000..3a95700f82 --- /dev/null +++ b/bits/winsize.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2023 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 + . */ + +#if !defined(_SYS_IOCTL_H) && !defined(_TERMIOS_H) +# error "Never use directly; include or instead." +#endif + +#ifndef _BITS_WINSIZE_H +#define _BITS_WINSIZE_H + +/* Type of ARG for TIOCGWINSZ and TIOCSWINSZ requests. */ +struct winsize +{ + unsigned short int ws_row; /* Rows, in characters. */ + unsigned short int ws_col; /* Columns, in characters. */ + + /* These are not actually used. */ + unsigned short int ws_xpixel; /* Horizontal pixels. */ + unsigned short int ws_ypixel; /* Vertical pixels. */ +}; + +#endif /* _BITS_WINSIZE_H */ diff --git a/sysdeps/unix/bsd/tcgetwinsize.c b/sysdeps/unix/bsd/tcgetwinsize.c new file mode 100644 index 0000000000..eeff1c7b9c --- /dev/null +++ b/sysdeps/unix/bsd/tcgetwinsize.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2023 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 + . */ + +#include + +/* Get the winsize of FD in *WINSIZE_P. */ +int +tcgetwinsize (int fd, struct winsize *winsize_p) +{ + return __ioctl (fd, TIOCGWINSZ, winsize_p); +} diff --git a/sysdeps/unix/bsd/tcsetwinsize.c b/sysdeps/unix/bsd/tcsetwinsize.c new file mode 100644 index 0000000000..e788a6d69a --- /dev/null +++ b/sysdeps/unix/bsd/tcsetwinsize.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2023 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 + . */ + +#include + +/* Set the winsize of FD to *WINSIZE_P. */ +int +tcsetwinsize (int fd, const struct winsize *winsize_p) +{ + return __ioctl (fd, TIOCSWINSZ, winsize_p); +} diff --git a/sysdeps/unix/sysv/linux/bits/ioctl-types.h b/sysdeps/unix/sysv/linux/bits/ioctl-types.h index 0984adbfdf..7626fde5be 100644 --- a/sysdeps/unix/sysv/linux/bits/ioctl-types.h +++ b/sysdeps/unix/sysv/linux/bits/ioctl-types.h @@ -23,14 +23,9 @@ /* Get definition of constants for use with `ioctl'. */ #include - -struct winsize - { - unsigned short int ws_row; - unsigned short int ws_col; - unsigned short int ws_xpixel; - unsigned short int ws_ypixel; - }; +/* Get the definition of 'struct winsize', which is the type of ARG for + TIOCGWINSZ and TIOCSWINSZ requests. */ +#include #define NCC 8 struct termio diff --git a/sysdeps/unix/sysv/linux/mips/bits/ioctl-types.h b/sysdeps/unix/sysv/linux/mips/bits/ioctl-types.h index 4b718537a6..2f65c2ba7f 100644 --- a/sysdeps/unix/sysv/linux/mips/bits/ioctl-types.h +++ b/sysdeps/unix/sysv/linux/mips/bits/ioctl-types.h @@ -23,13 +23,9 @@ /* Get definition of constants for use with `ioctl'. */ #include -struct winsize - { - unsigned short int ws_row; - unsigned short int ws_col; - unsigned short int ws_xpixel; - unsigned short int ws_ypixel; - }; +/* Get the definition of 'struct winsize', which is the type of ARG for + TIOCGWINSZ and TIOCSWINSZ requests. */ +#include #define NCC 8 struct termio diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h b/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h index a14b9511be..7e795c3dd6 100644 --- a/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h +++ b/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h @@ -23,14 +23,9 @@ /* Get definition of constants for use with `ioctl'. */ #include - -struct winsize - { - unsigned short int ws_row; - unsigned short int ws_col; - unsigned short int ws_xpixel; - unsigned short int ws_ypixel; - }; +/* Get the definition of 'struct winsize', which is the type of ARG for + TIOCGWINSZ and TIOCSWINSZ requests. */ +#include #define NCC 10 struct termio diff --git a/sysdeps/unix/sysv/linux/tcgetwinsize.c b/sysdeps/unix/sysv/linux/tcgetwinsize.c new file mode 100644 index 0000000000..460c5a5f2d --- /dev/null +++ b/sysdeps/unix/sysv/linux/tcgetwinsize.c @@ -0,0 +1 @@ +#include diff --git a/sysdeps/unix/sysv/linux/tcsetwinsize.c b/sysdeps/unix/sysv/linux/tcsetwinsize.c new file mode 100644 index 0000000000..562bc40439 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tcsetwinsize.c @@ -0,0 +1 @@ +#include diff --git a/termios/Makefile b/termios/Makefile index cd45fc7626..673ef9dfaa 100644 --- a/termios/Makefile +++ b/termios/Makefile @@ -26,7 +26,8 @@ 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 + tcdrain tcflow tcflush tcsendbrk cfmakeraw tcgetsid \ + tcgetwinsize tcsetwinsize include ../Rules diff --git a/termios/Versions b/termios/Versions index 711ed0334b..159d4a149e 100644 --- a/termios/Versions +++ b/termios/Versions @@ -11,4 +11,8 @@ libc { # t* tcgetsid; } + GLIBC_2.38 { + # t* + tcgetwinsize; tcsetwinsize; + } } diff --git a/termios/tcgetwinsize.c b/termios/tcgetwinsize.c new file mode 100644 index 0000000000..3a09659593 --- /dev/null +++ b/termios/tcgetwinsize.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2023 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 + . */ + +#include +#include + +/* Get the winsize of FD in *WINSIZE_P. */ +int +tcgetwinsize (int fd, struct winsize *winsize_p) +{ + if (fd < 0) + { + __set_errno (EBADF); + return -1; + } + if (winsize_p == NULL) + { + __set_errno (EINVAL); + return -1; + } + + __set_errno (ENOSYS); + return -1; +} +stub_warning (tcgetwinsize) diff --git a/termios/tcsetwinsize.c b/termios/tcsetwinsize.c new file mode 100644 index 0000000000..a2f30ffe07 --- /dev/null +++ b/termios/tcsetwinsize.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2023 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 + . */ + +#include +#include + +/* Set the winsize of FD to *WINSIZE_P. */ +int +tcsetwinsize (int fd, const struct winsize *winsize_p) +{ + if (fd < 0) + { + __set_errno (EBADF); + return -1; + } + if (winsize_p == NULL) + { + __set_errno (EINVAL); + return -1; + } + + __set_errno (ENOSYS); + return -1; +} +stub_warning (tcsetwinsize) diff --git a/termios/termios.h b/termios/termios.h index c974960580..1e972b292f 100644 --- a/termios/termios.h +++ b/termios/termios.h @@ -99,6 +99,17 @@ extern int tcflow (int __fd, int __action) __THROW; extern __pid_t tcgetsid (int __fd) __THROW; #endif +#ifdef __USE_GNU +/* Get the definition of 'struct winsize', which is the type of ARG for + TIOCGWINSZ and TIOCSWINSZ requests. */ +#include + +/* Get the winsize of FD in *WINSIZE_P. */ +extern int tcgetwinsize (int __fd, struct winsize *__winsize_p) __THROW; + +/* Set the winsize of FD to *WINSIZE_P. */ +extern int tcsetwinsize (int __fd, const struct winsize *__winsize_p) __THROW; +#endif #ifdef __USE_MISC # include -- 2.30.2