51 lines
901 B
C
51 lines
901 B
C
|
//#!/usr/local/bin/tcc -run
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <time.h>
|
||
|
#include <signal.h>
|
||
|
#include <string.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
const int BUFFSIZE = 128;
|
||
|
bool shouldrun = true;
|
||
|
|
||
|
void sighand(int sig) {
|
||
|
shouldrun = false;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char** argv) {
|
||
|
if(argc != 2) {
|
||
|
printf("Usage: %s logfile\n", argv[0]);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
int log = 1;
|
||
|
if(strcmp(argv[1], "-"))
|
||
|
log = open(argv[1], O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
|
||
|
|
||
|
signal(SIGINT, sighand);
|
||
|
|
||
|
int dev = open("/dev/input/mice", O_RDONLY);
|
||
|
|
||
|
time_t last = 0;
|
||
|
|
||
|
while(shouldrun) {
|
||
|
char buff[BUFFSIZE];
|
||
|
int r = read(dev, buff, BUFFSIZE);
|
||
|
time_t curr = time(NULL);
|
||
|
if(curr != last) {
|
||
|
//dprintf(log, "%ld\n", curr);
|
||
|
write(log, &curr, sizeof(curr));
|
||
|
last = curr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
close(dev);
|
||
|
if(log != 1)
|
||
|
close(log);
|
||
|
return 0;
|
||
|
}
|