loadkmap.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini loadkmap implementation for busybox
  4. *
  5. * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. *
  9. */
  10. #include "libbb.h"
  11. #define BINARY_KEYMAP_MAGIC "bkeymap"
  12. /* From <linux/kd.h> */
  13. struct kbentry {
  14. unsigned char kb_table;
  15. unsigned char kb_index;
  16. unsigned short kb_value;
  17. };
  18. /* sets one entry in translation table */
  19. #define KDSKBENT 0x4B47
  20. /* From <linux/keyboard.h> */
  21. #define NR_KEYS 128
  22. #define MAX_NR_KEYMAPS 256
  23. int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  24. int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  25. {
  26. struct kbentry ke;
  27. int i, j, fd;
  28. uint16_t ibuff[NR_KEYS];
  29. RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
  30. /* bb_warn_ignoring_args(argc>=2);*/
  31. fd = get_console_fd_or_die();
  32. xread(STDIN_FILENO, flags, 7);
  33. if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
  34. bb_error_msg_and_die("not a valid binary keymap");
  35. xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
  36. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  37. if (flags[i] == 1) {
  38. xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
  39. for (j = 0; j < NR_KEYS; j++) {
  40. ke.kb_index = j;
  41. ke.kb_table = i;
  42. ke.kb_value = ibuff[j];
  43. ioctl(fd, KDSKBENT, &ke);
  44. }
  45. }
  46. }
  47. if (ENABLE_FEATURE_CLEAN_UP) {
  48. close(fd);
  49. RELEASE_CONFIG_BUFFER(flags);
  50. }
  51. return EXIT_SUCCESS;
  52. }