Search This Blog

Wednesday, June 9, 2010

Add a system independent sleep/clock to your program

Add a system independent sleep/clock to your program

http://www.faqs.org/faqs/unix-faq/faq/part4/section-6.html

extern int        select();

int
usleep( usec ) /* returns 0 if ok, else -1 */
long usec; /* delay in microseconds */
{
static struct /* `timeval' */
{
long tv_sec; /* seconds */
long tv_usec; /* microsecs */
} delay; /* _select() timeout */

delay.tv_sec = usec / 1000000L;
delay.tv_usec = usec % 1000000L;

return select( 0, (long *)0, (long *)0, (long *)0, &delay );
}