home *** CD-ROM | disk | FTP | other *** search
- /*{{{}}}*/
- /*{{{ includes*/
- #ifdef _INCLUDE_HPUX_SOURCE
- # undef _POSIX_SOURCE
- #endif
-
- #ifdef CONFIG_H
- # define USLEEP_C
- # include "config.h"
- #endif
-
- #ifdef SELECT_USLEEP
- # include <sys/time.h>
- #else
- # ifdef POLL_USLEEP
- # include <poll.h>
- # else
- # ifdef BUSY_USLEEP
- # include <sys/time.h>
- # endif
- # endif
- #endif
- /*}}} */
-
- /*{{{ usleep*/
- #define sec ((unsigned long)1000000)
-
- int usleep(unsigned long t)
- { if (t>sec) { sleep((int)(t/sec));t%=sec; }
- if (t)
- # ifdef SELECT_USLEEP
- { struct timeval timeout;
-
- timeout.tv_sec=0;
- timeout.tv_usec=t;
- select((size_t)0,(void*)0,(void*)0,(void*)0,&timeout);
- }
- # else
- # ifdef POLL_USLEEP
- poll((struct pollfd*)0,(size_t)0,(int)(t/1000));
- # else
- # ifdef BUSY_USLEEP
- /*{{{ wait busy*/
- { struct timezone zone;
- struct timeval start;
-
- gettimeofday(&start,&zone);
- do
- { struct timeval end;
-
- gettimeofday(&end,&zone);
- if (start.tv_usec>end.tv_usec)
- { end.tv_usec+=sec;end.tv_usec--; }
- if ( ((end.tv_sec-start.tv_sec)>0)
- ||((end.tv_usec-start.tv_usec)>t)) t=0;
- }
- while (t);
- }
- /*}}} */
- # else
- sleep(1);
- # endif
- # endif
- # endif
- return(0);
- }
- /*}}} */
-