/******************************************************************** jusleep.c micro sleep implementation written by Jose Mari Reyes The function will wait up to the number of seconds or microseconds, you can override the sleeping process by hitting the enter key on line buffered terminal. returns -1 if override or 0 if complete param: seconds, micro seconds , 0 - override off 1 - override on (C)1998 by Jose Mari Reyes written this 12/20/1998 Contact at: web: www.angelfire.com/co2/xtechnica email: jet_reyes@jetemail.net wufei_ph@yahoo.com ********************************************************************/ #include #include #include #include #define STDIN 0 extern int jusleep(int seconds, int u_seconds, int override) { struct timeval tv; fd_set fds; tv.tv_sec = seconds; tv.tv_usec = u_seconds; FD_ZERO (&fds); FD_SET (STDIN, &fds); if (override == 0) select(STDIN , &fds, NULL, NULL, &tv); else if (override == 1) select(STDIN + 1, &fds, NULL, NULL, &tv); if (FD_ISSET(STDIN, &fds)) return -1; else return 0; }