+#ifdef UCLINUX
+void usleep_watchdevice(unsigned long usecs)
+{
+int err;
+fd_set readfds;
+struct timeval target,timeout;
+long timeout_sec,timeout_usec; /* signed! */
+
+ if (gettimeofday(&target/*tv*/,NULL/*tz*/))
+ perror("usleep_watchdevice()/gettimeofday(2) init");
+ target.tv_usec+=usecs%1000000;
+ target.tv_sec +=usecs/1000000 + (target.tv_usec/1000000);
+ target.tv_usec%=1000000;
+
+ for (;;) {
+ if (gettimeofday(&timeout/*tv*/,NULL/*tz*/))
+ perror("usleep_watchdevice()/gettimeofday(2) loop");
+
+ timeout_sec =target.tv_sec -(long)timeout.tv_sec ;
+ timeout_usec=target.tv_usec-(long)timeout.tv_usec;
+
+ if (timeout_usec<0) {
+ timeout_sec--;
+ timeout_usec+=1000000;
+ }
+ if (timeout_sec<0)
+ return;
+
+ timeout.tv_sec =timeout_sec ;
+ timeout.tv_usec=timeout_usec;
+
+ FD_ZERO(&readfds);
+ if (device_portfd>=0)
+ FD_SET(device_portfd,&readfds);
+
+ err=select((device_portfd<0 ? 0 : device_portfd+1),&readfds,NULL,NULL,&timeout);
+ if ( err > 0 ) {
+ if (device_portfd>=0 && FD_ISSET(device_portfd,&readfds)) {
+ /* call singal handler to process incoming data */
+ SigHandler(0);
+ }
+ } else {
+ if (err == -1)
+ perror("Error in SelectLoop");
+ }
+ }
+}
+#endif