wok annotate acpid/stuff/acpi_fakekey.c @ rev 3875

Busybox: ensure pidfile are valid
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Aug 10 13:56:55 2009 +0200 (2009-08-10)
parents
children
rev   line source
domcox@1512 1 #include <unistd.h>
domcox@1512 2 #include <fcntl.h>
domcox@1512 3 #include <string.h>
domcox@1512 4 #include <stdlib.h>
domcox@1512 5 #include <stdio.h>
domcox@1512 6 #include <linux/input.h>
domcox@1512 7
domcox@1512 8 #define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8)))
domcox@1512 9
domcox@1512 10 int find_keyboard() {
domcox@1512 11 int i, j;
domcox@1512 12 int fd;
domcox@1512 13 char filename[32];
domcox@1512 14 char key_bitmask[(KEY_MAX + 7) / 8];
domcox@1512 15
domcox@1512 16 for (i=0; i<32; i++) {
domcox@1512 17 snprintf(filename,sizeof(filename), "/dev/input/event%d", i);
domcox@1512 18
domcox@1512 19 fd = open(filename, O_RDWR);
domcox@1512 20 ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
domcox@1512 21
domcox@1512 22 for (j = 0; j < BTN_MISC; j++) {
domcox@1512 23 if (TestBit(j, key_bitmask))
domcox@1512 24 break;
domcox@1512 25 }
domcox@1512 26
domcox@1512 27 if (j < BTN_MISC) {
domcox@1512 28 return fd;
domcox@1512 29 }
domcox@1512 30 close (fd);
domcox@1512 31 }
domcox@1512 32 return 0;
domcox@1512 33 }
domcox@1512 34
domcox@1512 35 int main(int argc, char** argv) {
domcox@1512 36 int fd;
domcox@1512 37 int key;
domcox@1512 38 struct input_event event;
domcox@1512 39
domcox@1512 40 if (argc == 2) {
domcox@1512 41 key = atoi(argv[1]);
domcox@1512 42 } else {
domcox@1512 43 return 1;
domcox@1512 44 }
domcox@1512 45
domcox@1512 46 fd = find_keyboard();
domcox@1512 47
domcox@1512 48 if (!fd) {
domcox@1512 49 return 2;
domcox@1512 50 }
domcox@1512 51
domcox@1512 52 event.type = EV_KEY;
domcox@1512 53 event.code = key;
domcox@1512 54 event.value = 1;
domcox@1512 55 write(fd, &event, sizeof event);
domcox@1512 56
domcox@1512 57 event.type = EV_KEY;
domcox@1512 58 event.code = key;
domcox@1512 59 event.value = 0;
domcox@1512 60 write(fd, &event, sizeof event);
domcox@1512 61
domcox@1512 62 return 0;
domcox@1512 63 }
domcox@1512 64