summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2016-05-05 15:41:13 +0300
committerRan Benita <ran234@gmail.com>2016-05-05 15:41:13 +0300
commitfc41d3d6051db9feaa2abb27b1ba4988483ab90b (patch)
treee3fab2c535cf51f4c04c123d2c86e0da13f43575 /test
parent0da70c8d3c287eac041d52db8f1b69120b32c9ba (diff)
downloadxorg-lib-libxkbcommon-fc41d3d6051db9feaa2abb27b1ba4988483ab90b.tar.gz
test: use termios instead of system() for disabling terminal echo
Takes care of GCC's annoyingly persistent warn_unused_result warnings. But it's better to avoid system() I suppose. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/common.c23
-rw-r--r--test/interactive-evdev.c9
-rw-r--r--test/interactive-wayland.c5
-rw-r--r--test/interactive-x11.c4
-rw-r--r--test/test.h6
5 files changed, 35 insertions, 12 deletions
diff --git a/test/common.c b/test/common.c
index 8a2b632..2dd10a0 100644
--- a/test/common.c
+++ b/test/common.c
@@ -35,6 +35,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <termios.h>
#include "test.h"
@@ -454,3 +455,25 @@ test_print_state_changes(enum xkb_state_component changed)
printf("leds ");
printf("]\n");
}
+
+void
+test_disable_stdin_echo(void)
+{
+ /* Same as `stty -echo`. */
+ struct termios termios;
+ if (tcgetattr(STDIN_FILENO, &termios) == 0) {
+ termios.c_lflag &= ~ECHO;
+ (void) tcsetattr(STDIN_FILENO, TCSADRAIN, &termios);
+ }
+}
+
+void
+test_enable_stdin_echo(void)
+{
+ /* Same as `stty echo`. */
+ struct termios termios;
+ if (tcgetattr(STDIN_FILENO, &termios) == 0) {
+ termios.c_lflag |= ECHO;
+ (void) tcsetattr(STDIN_FILENO, TCSADRAIN, &termios);
+ }
+}
diff --git a/test/interactive-evdev.c b/test/interactive-evdev.c
index 7fdc069..7853e59 100644
--- a/test/interactive-evdev.c
+++ b/test/interactive-evdev.c
@@ -482,15 +482,10 @@ main(int argc, char *argv[])
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
- /* Instead of fiddling with termios.. */
- (void) system("stty -echo");
-
+ test_disable_stdin_echo();
ret = loop(kbds);
- if (ret)
- goto err_stty;
+ test_enable_stdin_echo();
-err_stty:
- (void) system("stty echo");
free_keyboards(kbds);
err_compose:
xkb_compose_table_unref(compose_table);
diff --git a/test/interactive-wayland.c b/test/interactive-wayland.c
index 5716291..1f3f409 100644
--- a/test/interactive-wayland.c
+++ b/test/interactive-wayland.c
@@ -680,14 +680,13 @@ main(int argc, char *argv[])
goto err_conn;
}
- (void) system("stty -echo");
+ test_disable_stdin_echo();
do {
ret = wl_display_dispatch(inter.dpy);
} while (ret >= 0 && !terminate);
- (void) system("stty echo");
+ test_enable_stdin_echo();
wl_registry_destroy(registry);
-
err_conn:
dpy_disconnect(&inter);
err_out:
diff --git a/test/interactive-x11.c b/test/interactive-x11.c
index 34ad654..904136f 100644
--- a/test/interactive-x11.c
+++ b/test/interactive-x11.c
@@ -372,9 +372,9 @@ main(int argc, char *argv[])
goto err_core_kbd;
}
- (void) system("stty -echo");
+ test_disable_stdin_echo();
ret = loop(conn, &core_kbd);
- (void) system("stty echo");
+ test_enable_stdin_echo();
err_core_kbd:
deinit_kbd(&core_kbd);
diff --git a/test/test.h b/test/test.h
index 628ec18..440c7ea 100644
--- a/test/test.h
+++ b/test/test.h
@@ -88,3 +88,9 @@ test_print_keycode_state(struct xkb_state *state,
void
test_print_state_changes(enum xkb_state_component changed);
+
+void
+test_disable_stdin_echo(void);
+
+void
+test_enable_stdin_echo(void);