【代码清单】
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
int main(void){
int fd,retval;
char buf[6];
fd_set readfds,tmp_readfds;
struct timeval tv;
if((fd=open("/dev/input/mice",O_RDONLY|O_NONBLOCK))<0){
printf("Fail to open /dev/input/mice!\n");
return -1;
}
printf("Open /dev/input/mice success!\n");
tv.tv_sec=5;
tv.tv_usec=0;
FD_ZERO(&readfds);
FD_SET(fd,&readfds);
FD_SET(0,&readfds);
while(FD_ISSET(fd,&readfds)){
tmp_readfds=readfds;
retval=select(fd+1,&readfds,NULL,NULL,&tv);
printf("retval is %d.\n",&retval);
switch(retval){
case -1:
{
printf("Select error\n");
return -1;
}
break;
case 0:
{
printf("Time out\n");
return -1;
}
break;
default:{