MSVC: Provide implementations of test_{dis,en}able_stdin_echo This provides implementations of the test_enable_stdin_echo and test_disable_stdin_echo which do not require <termios.h>, which is not available on Windows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/test/common.c b/test/common.c
index 446ce58..15a4fe0 100644
--- a/test/common.c
+++ b/test/common.c
@@ -34,14 +34,15 @@
#include <limits.h>
#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#ifdef _MSC_VER
#include <io.h>
+#include <windows.h>
#else
#include <unistd.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
#include <termios.h>
+#endif
#include "test.h"
#include "utils.h"
@@ -468,6 +469,25 @@ test_print_state_changes(enum xkb_state_component changed)
printf("]\n");
}
+#ifdef _MSC_VER
+void
+test_disable_stdin_echo(void)
+{
+ HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD mode = 0;
+ GetConsoleMode(stdin_handle, &mode);
+ SetConsoleMode(stdin_handle, mode & ~ENABLE_ECHO_INPUT);
+}
+
+void
+test_enable_stdin_echo(void)
+{
+ HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD mode = 0;
+ GetConsoleMode(stdin_handle, &mode);
+ SetConsoleMode(stdin_handle, mode | ENABLE_ECHO_INPUT);
+}
+#else
void
test_disable_stdin_echo(void)
{
@@ -489,3 +509,4 @@ test_enable_stdin_echo(void)
(void) tcsetattr(STDIN_FILENO, TCSADRAIN, &termios);
}
}
+#endif