Remove building with NOCRYPTO option
[minix3.git] / minix / commands / loadkeys / loadkeys.c
blob38468ba066d4b9db8d8973a23fd24d3f33cb0e02
1 /* loadkeys - load national keyboard map Author: Marcus Hampel
2 */
3 #include <sys/types.h>
4 #include <sys/ioctl.h>
5 #include <minix/keymap.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <errno.h>
13 #define KBD_DEVICE "/dev/console"
15 void fatal(char *say)
17 fprintf(stderr, "loadkeys: %s: %s\n", say, strerror(errno));
18 exit(EXIT_FAILURE);
22 void usage(void)
24 fprintf(stderr, "usage: loadkeys <mapfile>\n");
25 exit(EXIT_FAILURE);
29 int main(int argc, char *argv[])
31 char sig[4];
32 keymap_t keymap;
33 int fd;
35 if (argc != 2)
36 usage();
38 if ((fd = open(argv[1], O_RDONLY)) < 0) fatal(argv[1]);
40 if (read(fd, sig, sizeof(sig)) < sizeof(sig)) fatal(argv[1]);
42 if (memcmp(sig, KEY_MAGIC, sizeof(sig)) != 0) {
43 fprintf(stderr, "loadkeys: %s: not a keymap file\n", argv[1]);
44 return EXIT_FAILURE;
47 if (read(fd, keymap, sizeof(keymap)) < sizeof(keymap)) fatal(argv[1]);
49 close(fd);
51 if ((fd = open(KBD_DEVICE, O_WRONLY)) < 0) fatal(KBD_DEVICE);
53 if (ioctl(fd, KIOCSMAP, keymap) < 0) fatal(KBD_DEVICE);
55 return EXIT_SUCCESS;