loadkmap.c revision 1.9
1/* $NetBSD: loadkmap.c,v 1.9 2011/05/19 02:56:03 christos Exp $ */ 2 3#include <sys/types.h> 4#include <sys/stat.h> 5#include <sys/ioctl.h> 6#include "../../dev/iteioctl.h" 7#include "../../dev/kbdmap.h" 8#include <stdio.h> 9#include <stdlib.h> 10#include <unistd.h> 11#include <fcntl.h> 12 13int load_kmap(const char *, int); 14int dump_kmap(void); 15 16int 17main(int argc, char *argv[]) 18{ 19 int set_sysmap = 0; 20 char *mapfile; 21 int rc = 0; 22 23 if (argc > 2) { 24 if ((argc == 3) && !strcmp(argv[1], "-f")) { 25 mapfile = argv[2]; 26 set_sysmap = 1; 27 } 28 else { 29 fprintf(stderr, "%s [-f] keymap\n", argv[0]); 30 exit(1); 31 } 32 } 33 else mapfile = argv[1]; 34 35 if (argc == 1) 36 rc = dump_kmap(); 37 else rc = load_kmap(mapfile, set_sysmap); 38 39 exit (rc); 40} 41 42 43int 44load_kmap(const char *file, int set_sysmap) 45{ 46 int fd; 47 char buf[sizeof (struct kbdmap)]; 48 int ioc; 49 50 ioc = set_sysmap ? ITEIOCSSKMAP : ITEIOCSKMAP; 51 52 if ((fd = open (file, 0)) >= 0) { 53 if (read (fd, buf, sizeof (buf)) == sizeof (buf)) { 54 if (ioctl (0, ioc, buf) == 0) { 55 close(fd); 56 return 0; 57 } 58 else perror("ITEIOCSKMAP"); 59 } 60 else perror("read kmap"); 61 62 close(fd); 63 } 64 else perror("open kmap"); 65 return 1; 66} 67 68int 69dump_kmap(void) 70{ 71 char buf[sizeof (struct kbdmap)]; 72 73 if (ioctl (0, ITEIOCGKMAP, buf) == 0) { 74 write (1, buf, sizeof (buf)); 75 return 0; 76 } 77 perror ("ITEIOCGKMAP"); 78 return 1; 79} 80