diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-11-21 09:27:02 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-11-21 09:27:02 +0000 |
commit | acbdc47aac6c01d15522e8c921cd010b8ea958d6 (patch) | |
tree | 8424826bfd1129602178a9813bcb4f55126e7a50 /console-tools/loadkmap.c | |
parent | 2cd1eb16ad0131674251eeceed23298e29361d51 (diff) | |
download | busybox-w32-acbdc47aac6c01d15522e8c921cd010b8ea958d6.tar.gz busybox-w32-acbdc47aac6c01d15522e8c921cd010b8ea958d6.tar.bz2 busybox-w32-acbdc47aac6c01d15522e8c921cd010b8ea958d6.zip |
Make use of libbb functions bb_xopen, bb_full_read, used #define's
instead of static consts, avoid xmalloc.
Diffstat (limited to 'console-tools/loadkmap.c')
-rw-r--r-- | console-tools/loadkmap.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c index f4208df63..5b2f31abc 100644 --- a/console-tools/loadkmap.c +++ b/console-tools/loadkmap.c | |||
@@ -37,43 +37,35 @@ struct kbentry { | |||
37 | unsigned char kb_index; | 37 | unsigned char kb_index; |
38 | unsigned short kb_value; | 38 | unsigned short kb_value; |
39 | }; | 39 | }; |
40 | static const int KDSKBENT = 0x4B47; /* sets one entry in translation table */ | 40 | /* sets one entry in translation table */ |
41 | #define KDSKBENT 0x4B47 | ||
41 | 42 | ||
42 | /* From <linux/keyboard.h> */ | 43 | /* From <linux/keyboard.h> */ |
43 | static const int NR_KEYS = 128; | 44 | #define NR_KEYS 128 |
44 | static const int MAX_NR_KEYMAPS = 256; | 45 | #define MAX_NR_KEYMAPS 256 |
45 | 46 | ||
46 | int loadkmap_main(int argc, char **argv) | 47 | int loadkmap_main(int argc, char **argv) |
47 | { | 48 | { |
48 | struct kbentry ke; | 49 | struct kbentry ke; |
49 | u_short *ibuff; | 50 | int i, j, fd; |
50 | int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short); | 51 | u_short ibuff[NR_KEYS]; |
51 | char flags[MAX_NR_KEYMAPS], buff[7]; | 52 | char flags[MAX_NR_KEYMAPS]; |
53 | char buff[7]; | ||
52 | 54 | ||
53 | if (argc != 1) | 55 | if (argc != 1) |
54 | bb_show_usage(); | 56 | bb_show_usage(); |
55 | 57 | ||
56 | fd = open(CURRENT_VC, O_RDWR); | 58 | fd = bb_xopen(CURRENT_VC, O_RDWR); |
57 | if (fd < 0) | ||
58 | bb_perror_msg_and_die("Error opening " CURRENT_VC); | ||
59 | 59 | ||
60 | read(0, buff, 7); | 60 | if ((bb_full_read(0, buff, 7) != 7) || (strncmp(buff, BINARY_KEYMAP_MAGIC, 7) != 0)) |
61 | if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) | ||
62 | bb_error_msg_and_die("This is not a valid binary keymap."); | 61 | bb_error_msg_and_die("This is not a valid binary keymap."); |
63 | 62 | ||
64 | if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) | 63 | if (bb_full_read(0, flags, MAX_NR_KEYMAPS) != MAX_NR_KEYMAPS) |
65 | bb_perror_msg_and_die("Error reading keymap flags"); | 64 | bb_perror_msg_and_die("Error reading keymap flags"); |
66 | 65 | ||
67 | ibuff = (u_short *) xmalloc(ibuffsz); | ||
68 | |||
69 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | 66 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
70 | if (flags[i] == 1) { | 67 | if (flags[i] == 1) { |
71 | pos = 0; | 68 | bb_full_read(0, ibuff, NR_KEYS * sizeof(u_short)); |
72 | while (pos < ibuffsz) { | ||
73 | if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0) | ||
74 | bb_perror_msg_and_die("Error reading keymap"); | ||
75 | pos += readsz; | ||
76 | } | ||
77 | for (j = 0; j < NR_KEYS; j++) { | 69 | for (j = 0; j < NR_KEYS; j++) { |
78 | ke.kb_index = j; | 70 | ke.kb_index = j; |
79 | ke.kb_table = i; | 71 | ke.kb_table = i; |
@@ -82,6 +74,7 @@ int loadkmap_main(int argc, char **argv) | |||
82 | } | 74 | } |
83 | } | 75 | } |
84 | } | 76 | } |
77 | |||
85 | /* Don't bother to close files. Exit does that | 78 | /* Don't bother to close files. Exit does that |
86 | * automagically, so we can save a few bytes */ | 79 | * automagically, so we can save a few bytes */ |
87 | /* close(fd); */ | 80 | /* close(fd); */ |