2 * Mini loadkmap implementation for busybox
4 * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/keyboard.h>
28 #include <sys/ioctl.h>
31 static const char loadkmap_usage[] = "loadkmap\n"
33 "\tLoad a binary keyboard translation table from standard input.\n"
38 loadkmap_main(int argc, char * * argv)
42 int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
43 char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
45 fd = open("/dev/tty0", O_RDWR);
47 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
52 if (0 != strncmp(buff,magic,7)) {
53 fprintf(stderr, "This is not a valid binary keymap.\n");
57 if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) {
58 fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno));
62 ibuff=(u_short *) malloc(ibuffsz);
64 fprintf(stderr, "Out of memory.\n");
68 for(i=0; i<MAX_NR_KEYMAPS; i++) {
71 while (pos < ibuffsz) {
72 if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
73 fprintf(stderr, "Error reading keymap: %s\n",
79 for(j=0; j<NR_KEYS; j++) {
82 ke.kb_value = ibuff[j];
83 ioctl(fd, KDSKBENT, &ke);