From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8EEE8158137 for ; Sun, 11 Jun 2023 16:47:17 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CD9FDE088C; Sun, 11 Jun 2023 16:47:16 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id AFFC0E0872 for ; Sun, 11 Jun 2023 16:47:16 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C26433413DE for ; Sun, 11 Jun 2023 16:47:15 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5FEDAA85 for ; Sun, 11 Jun 2023 16:47:14 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1686472336.a608aa2b90299f74dbced4a31822aff7e4dc30ff.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: ecma48-cpr.c X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: a608aa2b90299f74dbced4a31822aff7e4dc30ff X-VCS-Branch: master Date: Sun, 11 Jun 2023 16:47:14 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 166e6afa-3ced-4382-a4f1-1e27a4c6f1b8 X-Archives-Hash: 08118189c8c3009944105343db21c534 commit: a608aa2b90299f74dbced4a31822aff7e4dc30ff Author: Kerin Millar plushkava net> AuthorDate: Sat Jun 10 23:21:58 2023 +0000 Commit: Sam James gentoo org> CommitDate: Sun Jun 11 08:32:16 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=a608aa2b ecma48-cpr: Flush the input queue with tcsetattr(3) instead Doing so saves an additional syscall and waits for the output queue to be drained, which is no bad thing. Signed-off-by: Kerin Millar plushkava.net> ecma48-cpr.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ecma48-cpr.c b/ecma48-cpr.c index 144c4ea..813621e 100644 --- a/ecma48-cpr.c +++ b/ecma48-cpr.c @@ -93,10 +93,8 @@ main(void) { /* * Try to apply the new terminal settings. */ - if (tcsetattr(STDIN_FILENO, TCSANOW, &new_tty) != 0) { + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new_tty) != 0) { die("failed to modify the terminal settings"); - } else if (tcflush(STDIN_FILENO, TCIFLUSH) != 0) { - die("failed to flush the terminal's input queue"); } else if (fprintf(tty, "\033[6n") != 4) { die("failed to write the CPR sequence to the terminal"); } else if (fclose(tty) != 0) { @@ -214,7 +212,7 @@ static void cleanup(void) { bool const is_saved = is_tty_saved; if (is_saved) { - tcsetattr(STDIN_FILENO, TCSANOW, &save_tty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &save_tty); is_tty_saved = false; } }