diff options
Diffstat (limited to 'console-tools/kbd_mode.c')
-rw-r--r-- | console-tools/kbd_mode.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c index 13a82d7fa..c8451e72d 100644 --- a/console-tools/kbd_mode.c +++ b/console-tools/kbd_mode.c | |||
@@ -7,26 +7,26 @@ | |||
7 | * console-utils v0.2.3, licensed under GNU GPLv2 | 7 | * console-utils v0.2.3, licensed under GNU GPLv2 |
8 | * | 8 | * |
9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
10 | * | ||
11 | */ | 10 | */ |
12 | |||
13 | #include "libbb.h" | 11 | #include "libbb.h" |
14 | #include <linux/kd.h> | 12 | #include <linux/kd.h> |
15 | 13 | ||
16 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 14 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
17 | int kbd_mode_main(int argc UNUSED_PARAM, char **argv) | 15 | int kbd_mode_main(int argc UNUSED_PARAM, char **argv) |
18 | { | 16 | { |
19 | int fd; | ||
20 | unsigned opt; | ||
21 | enum { | 17 | enum { |
22 | SCANCODE = (1 << 0), | 18 | SCANCODE = (1 << 0), |
23 | ASCII = (1 << 1), | 19 | ASCII = (1 << 1), |
24 | MEDIUMRAW = (1 << 2), | 20 | MEDIUMRAW = (1 << 2), |
25 | UNICODE = (1 << 3) | 21 | UNICODE = (1 << 3), |
26 | }; | 22 | }; |
27 | static const char KD_xxx[] ALIGN1 = "saku"; | 23 | int fd; |
28 | opt = getopt32(argv, KD_xxx); | 24 | unsigned opt; |
29 | fd = get_console_fd_or_die(); | 25 | const char *tty_name = CURRENT_TTY; |
26 | |||
27 | opt = getopt32(argv, "sakuC:", &tty_name); | ||
28 | fd = xopen(tty_name, O_NONBLOCK); | ||
29 | opt &= 0xf; /* clear -C bit, see (*) */ | ||
30 | 30 | ||
31 | if (!opt) { /* print current setting */ | 31 | if (!opt) { /* print current setting */ |
32 | const char *mode = "unknown"; | 32 | const char *mode = "unknown"; |
@@ -43,6 +43,7 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv) | |||
43 | mode = "Unicode (UTF-8)"; | 43 | mode = "Unicode (UTF-8)"; |
44 | printf("The keyboard is in %s mode\n", mode); | 44 | printf("The keyboard is in %s mode\n", mode); |
45 | } else { | 45 | } else { |
46 | /* here we depend on specific bits assigned to options (*) */ | ||
46 | opt = opt & UNICODE ? 3 : opt >> 1; | 47 | opt = opt & UNICODE ? 3 : opt >> 1; |
47 | /* double cast prevents warnings about widening conversion */ | 48 | /* double cast prevents warnings about widening conversion */ |
48 | xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt); | 49 | xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt); |