Cleaned up error handling, TRUE/FALSE usage, and other minor issues.
This commit is contained in:
parent
3180413e76
commit
9133c98a9d
@ -26,6 +26,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#define BINARY_KEYMAP_MAGIC "bkeymap"
|
||||||
|
|
||||||
/* From <linux/kd.h> */
|
/* From <linux/kd.h> */
|
||||||
struct kbentry {
|
struct kbentry {
|
||||||
unsigned char kb_table;
|
unsigned char kb_table;
|
||||||
@ -43,29 +45,21 @@ int loadkmap_main(int argc, char **argv)
|
|||||||
struct kbentry ke;
|
struct kbentry ke;
|
||||||
u_short *ibuff;
|
u_short *ibuff;
|
||||||
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
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);
|
usage(loadkmap_usage);
|
||||||
}
|
|
||||||
|
|
||||||
fd = open("/dev/tty0", O_RDWR);
|
fd = open("/dev/tty0", O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
|
fatalPerror("Error opening /dev/tty0");
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
read(0, buff, 7);
|
read(0, buff, 7);
|
||||||
if (0 != strncmp(buff, magic, 7)) {
|
if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
|
||||||
errorMsg("This is not a valid binary keymap.\n");
|
fatalError("This is not a valid binary keymap.\n");
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
|
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS))
|
||||||
errorMsg("Error reading keymap flags: %s\n",
|
fatalPerror("Error reading keymap flags");
|
||||||
strerror(errno));
|
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ibuff = (u_short *) xmalloc(ibuffsz);
|
ibuff = (u_short *) xmalloc(ibuffsz);
|
||||||
|
|
||||||
@ -73,12 +67,8 @@ int loadkmap_main(int argc, char **argv)
|
|||||||
if (flags[i] == 1) {
|
if (flags[i] == 1) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
while (pos < ibuffsz) {
|
while (pos < ibuffsz) {
|
||||||
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
|
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0)
|
||||||
< 0) {
|
fatalPerror("Error reading keymap");
|
||||||
errorMsg("Error reading keymap: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
pos += readsz;
|
pos += readsz;
|
||||||
}
|
}
|
||||||
for (j = 0; j < NR_KEYS; j++) {
|
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
|
/* Don't bother to close files. Exit does that
|
||||||
* automagically, so we can save a few bytes */
|
* automagically, so we can save a few bytes */
|
||||||
/* close(fd); */
|
/* close(fd); */
|
||||||
return(TRUE);
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
36
loadkmap.c
36
loadkmap.c
@ -26,6 +26,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#define BINARY_KEYMAP_MAGIC "bkeymap"
|
||||||
|
|
||||||
/* From <linux/kd.h> */
|
/* From <linux/kd.h> */
|
||||||
struct kbentry {
|
struct kbentry {
|
||||||
unsigned char kb_table;
|
unsigned char kb_table;
|
||||||
@ -43,29 +45,21 @@ int loadkmap_main(int argc, char **argv)
|
|||||||
struct kbentry ke;
|
struct kbentry ke;
|
||||||
u_short *ibuff;
|
u_short *ibuff;
|
||||||
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
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);
|
usage(loadkmap_usage);
|
||||||
}
|
|
||||||
|
|
||||||
fd = open("/dev/tty0", O_RDWR);
|
fd = open("/dev/tty0", O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
|
fatalPerror("Error opening /dev/tty0");
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
read(0, buff, 7);
|
read(0, buff, 7);
|
||||||
if (0 != strncmp(buff, magic, 7)) {
|
if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
|
||||||
errorMsg("This is not a valid binary keymap.\n");
|
fatalError("This is not a valid binary keymap.\n");
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
|
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS))
|
||||||
errorMsg("Error reading keymap flags: %s\n",
|
fatalPerror("Error reading keymap flags");
|
||||||
strerror(errno));
|
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ibuff = (u_short *) xmalloc(ibuffsz);
|
ibuff = (u_short *) xmalloc(ibuffsz);
|
||||||
|
|
||||||
@ -73,12 +67,8 @@ int loadkmap_main(int argc, char **argv)
|
|||||||
if (flags[i] == 1) {
|
if (flags[i] == 1) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
while (pos < ibuffsz) {
|
while (pos < ibuffsz) {
|
||||||
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
|
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0)
|
||||||
< 0) {
|
fatalPerror("Error reading keymap");
|
||||||
errorMsg("Error reading keymap: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
exit(FALSE);
|
|
||||||
}
|
|
||||||
pos += readsz;
|
pos += readsz;
|
||||||
}
|
}
|
||||||
for (j = 0; j < NR_KEYS; j++) {
|
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
|
/* Don't bother to close files. Exit does that
|
||||||
* automagically, so we can save a few bytes */
|
* automagically, so we can save a few bytes */
|
||||||
/* close(fd); */
|
/* close(fd); */
|
||||||
return(TRUE);
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user