commit:     a608aa2b90299f74dbced4a31822aff7e4dc30ff
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jun 10 23:21:58 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> 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 <kfm <AT> 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;
        }
 }

Reply via email to