diff options
author | Matt Kraai <kraai@debian.org> | 2000-10-25 16:48:15 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-10-25 16:48:15 +0000 |
commit | 9133c98a9d5b26fd645d30f70c4cf994aea972e9 (patch) | |
tree | b030ab95457996fb9dd41ab65c81ea7dae82d581 | |
parent | 3180413e7643dcb9ae38a617bf531557f64b3c57 (diff) |
Cleaned up error handling, TRUE/FALSE usage, and other minor issues.
-rw-r--r-- | console-tools/loadkmap.c | 36 | ||||
-rw-r--r-- | loadkmap.c | 36 |
2 files changed, 26 insertions, 46 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 @@ #include <stdio.h> #include <sys/ioctl.h> +#define BINARY_KEYMAP_MAGIC "bkeymap" + /* From <linux/kd.h> */ struct kbentry { unsigned char kb_table; @@ -43,29 +45,21 @@ int loadkmap_main(int argc, char **argv) struct kbentry ke; u_short *ibuff; int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short); - char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7]; + char flags[MAX_NR_KEYMAPS], buff[7]; - if (argc>=2 && *argv[1]=='-') { + if (argc != 1) usage(loadkmap_usage); - } fd = open("/dev/tty0", O_RDWR); - if (fd < 0) { - errorMsg("Error opening /dev/tty0: %s\n", strerror(errno)); - exit(FALSE); - } + if (fd < 0) + fatalPerror("Error opening /dev/tty0"); read(0, buff, 7); - if (0 != strncmp(buff, magic, 7)) { - errorMsg("This is not a valid binary keymap.\n"); - exit(FALSE); - } + if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) + fatalError("This is not a valid binary keymap.\n"); - if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) { - errorMsg("Error reading keymap flags: %s\n", - strerror(errno)); - exit(FALSE); - } + if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) + fatalPerror("Error reading keymap flags"); ibuff = (u_short *) xmalloc(ibuffsz); @@ -73,12 +67,8 @@ int loadkmap_main(int argc, char **argv) if (flags[i] == 1) { pos = 0; while (pos < ibuffsz) { - if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) - < 0) { - errorMsg("Error reading keymap: %s\n", - strerror(errno)); - exit(FALSE); - } + if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0) + fatalPerror("Error reading keymap"); pos += readsz; } for (j = 0; j < NR_KEYS; j++) { @@ -92,5 +82,5 @@ int loadkmap_main(int argc, char **argv) /* Don't bother to close files. Exit does that * automagically, so we can save a few bytes */ /* close(fd); */ - return(TRUE); + return EXIT_SUCCESS; } diff --git a/loadkmap.c b/loadkmap.c index 3f8d726e0..7dfa670f4 100644 --- a/loadkmap.c +++ b/loadkmap.c @@ -26,6 +26,8 @@ #include <stdio.h> #include <sys/ioctl.h> +#define BINARY_KEYMAP_MAGIC "bkeymap" + /* From <linux/kd.h> */ struct kbentry { unsigned char kb_table; @@ -43,29 +45,21 @@ int loadkmap_main(int argc, char **argv) struct kbentry ke; u_short *ibuff; int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short); - char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7]; + char flags[MAX_NR_KEYMAPS], buff[7]; - if (argc>=2 && *argv[1]=='-') { + if (argc != 1) usage(loadkmap_usage); - } fd = open("/dev/tty0", O_RDWR); - if (fd < 0) { - errorMsg("Error opening /dev/tty0: %s\n", strerror(errno)); - exit(FALSE); - } + if (fd < 0) + fatalPerror("Error opening /dev/tty0"); read(0, buff, 7); - if (0 != strncmp(buff, magic, 7)) { - errorMsg("This is not a valid binary keymap.\n"); - exit(FALSE); - } + if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) + fatalError("This is not a valid binary keymap.\n"); - if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) { - errorMsg("Error reading keymap flags: %s\n", - strerror(errno)); - exit(FALSE); - } + if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) + fatalPerror("Error reading keymap flags"); ibuff = (u_short *) xmalloc(ibuffsz); @@ -73,12 +67,8 @@ int loadkmap_main(int argc, char **argv) if (flags[i] == 1) { pos = 0; while (pos < ibuffsz) { - if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) - < 0) { - errorMsg("Error reading keymap: %s\n", - strerror(errno)); - exit(FALSE); - } + if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0) + fatalPerror("Error reading keymap"); pos += readsz; } for (j = 0; j < NR_KEYS; j++) { @@ -92,5 +82,5 @@ int loadkmap_main(int argc, char **argv) /* Don't bother to close files. Exit does that * automagically, so we can save a few bytes */ /* close(fd); */ - return(TRUE); + return EXIT_SUCCESS; } |