diff options
| author | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-10-25 16:48:15 +0000 |
|---|---|---|
| committer | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-10-25 16:48:15 +0000 |
| commit | bc92f429cb063af433650a4972ddf1d63d3cabf1 (patch) | |
| tree | b030ab95457996fb9dd41ab65c81ea7dae82d581 /console-tools/loadkmap.c | |
| parent | 2074e13dbe7fa441f95485ab3364e01d21437faf (diff) | |
| download | busybox-w32-bc92f429cb063af433650a4972ddf1d63d3cabf1.tar.gz busybox-w32-bc92f429cb063af433650a4972ddf1d63d3cabf1.tar.bz2 busybox-w32-bc92f429cb063af433650a4972ddf1d63d3cabf1.zip | |
Cleaned up error handling, TRUE/FALSE usage, and other minor issues.
git-svn-id: svn://busybox.net/trunk/busybox@1238 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'console-tools/loadkmap.c')
| -rw-r--r-- | console-tools/loadkmap.c | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c index 3f8d726e0..7dfa670f4 100644 --- a/console-tools/loadkmap.c +++ b/console-tools/loadkmap.c | |||
| @@ -26,6 +26,8 @@ | |||
| 26 | #include <stdio.h> | 26 | #include <stdio.h> |
| 27 | #include <sys/ioctl.h> | 27 | #include <sys/ioctl.h> |
| 28 | 28 | ||
| 29 | #define BINARY_KEYMAP_MAGIC "bkeymap" | ||
| 30 | |||
| 29 | /* From <linux/kd.h> */ | 31 | /* From <linux/kd.h> */ |
| 30 | struct kbentry { | 32 | struct kbentry { |
| 31 | unsigned char kb_table; | 33 | unsigned char kb_table; |
| @@ -43,29 +45,21 @@ int loadkmap_main(int argc, char **argv) | |||
| 43 | struct kbentry ke; | 45 | struct kbentry ke; |
| 44 | u_short *ibuff; | 46 | u_short *ibuff; |
| 45 | int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short); | 47 | int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short); |
| 46 | char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7]; | 48 | char flags[MAX_NR_KEYMAPS], buff[7]; |
| 47 | 49 | ||
| 48 | if (argc>=2 && *argv[1]=='-') { | 50 | if (argc != 1) |
| 49 | usage(loadkmap_usage); | 51 | usage(loadkmap_usage); |
| 50 | } | ||
| 51 | 52 | ||
| 52 | fd = open("/dev/tty0", O_RDWR); | 53 | fd = open("/dev/tty0", O_RDWR); |
| 53 | if (fd < 0) { | 54 | if (fd < 0) |
| 54 | errorMsg("Error opening /dev/tty0: %s\n", strerror(errno)); | 55 | fatalPerror("Error opening /dev/tty0"); |
| 55 | exit(FALSE); | ||
| 56 | } | ||
| 57 | 56 | ||
| 58 | read(0, buff, 7); | 57 | read(0, buff, 7); |
| 59 | if (0 != strncmp(buff, magic, 7)) { | 58 | if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) |
| 60 | errorMsg("This is not a valid binary keymap.\n"); | 59 | fatalError("This is not a valid binary keymap.\n"); |
| 61 | exit(FALSE); | ||
| 62 | } | ||
| 63 | 60 | ||
| 64 | if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) { | 61 | if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) |
| 65 | errorMsg("Error reading keymap flags: %s\n", | 62 | fatalPerror("Error reading keymap flags"); |
| 66 | strerror(errno)); | ||
| 67 | exit(FALSE); | ||
| 68 | } | ||
| 69 | 63 | ||
| 70 | ibuff = (u_short *) xmalloc(ibuffsz); | 64 | ibuff = (u_short *) xmalloc(ibuffsz); |
| 71 | 65 | ||
| @@ -73,12 +67,8 @@ int loadkmap_main(int argc, char **argv) | |||
| 73 | if (flags[i] == 1) { | 67 | if (flags[i] == 1) { |
| 74 | pos = 0; | 68 | pos = 0; |
| 75 | while (pos < ibuffsz) { | 69 | while (pos < ibuffsz) { |
| 76 | if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) | 70 | if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0) |
| 77 | < 0) { | 71 | fatalPerror("Error reading keymap"); |
| 78 | errorMsg("Error reading keymap: %s\n", | ||
| 79 | strerror(errno)); | ||
| 80 | exit(FALSE); | ||
| 81 | } | ||
| 82 | pos += readsz; | 72 | pos += readsz; |
| 83 | } | 73 | } |
| 84 | for (j = 0; j < NR_KEYS; j++) { | 74 | for (j = 0; j < NR_KEYS; j++) { |
| @@ -92,5 +82,5 @@ int loadkmap_main(int argc, char **argv) | |||
| 92 | /* Don't bother to close files. Exit does that | 82 | /* Don't bother to close files. Exit does that |
| 93 | * automagically, so we can save a few bytes */ | 83 | * automagically, so we can save a few bytes */ |
| 94 | /* close(fd); */ | 84 | /* close(fd); */ |
| 95 | return(TRUE); | 85 | return EXIT_SUCCESS; |
| 96 | } | 86 | } |
