3 * usleep -- This is the precision timer for Test Set
4 * Automation. It uses the select(2) system
5 * call to delay for the desired number of
6 * micro-seconds. This call returns ZERO
7 * (which is usually ignored) on successful
8 * completion, -1 otherwise.
11 * 1) We range check the passed in microseconds and log a
12 * warning message if appropriate. We then return without
13 * delay, flagging an error.
14 * 2) Load the Seconds and micro-seconds portion of the
15 * interval timer structure.
16 * 3) Call select(2) with no file descriptors set, just the
17 * timer, this results in either delaying the proper
18 * ammount of time or being interupted early by a signal.
21 * Added when the need for a subsecond timer was evident.
24 * Michael J. Dyer <mike@sherlock.med.ge.com>
35 #include <sys/param.h>
36 #include <sys/types.h>
39 usleep (unsigned long microSeconds)
41 unsigned int Seconds, uSec;
43 fd_set readfds, writefds, exceptfds;
46 if( (microSeconds == (unsigned long) 0) ||
47 microSeconds > (unsigned long) 4000000 )
49 errno = ERANGE; /* value out of range */
50 perror( "usleep time out of range ( 0 -> 4000000 ) " );
54 Seconds = microSeconds / (unsigned long) 1000000;
55 uSec = microSeconds % (unsigned long) 1000000;
57 Timer.tv_sec = Seconds;
60 if( select( nfds, &readfds, &writefds, &exceptfds, &Timer ) < 0 )
62 perror( "usleep (select) failed" );
69 #endif /* not HAVE_USLEEP */