editor: #undef O after use
[0verkill.git] / time.c
blobf97bb55fbcdcdd339689e4f440df367e612f63e7
1 #ifdef __EMX__
2 #include <stdlib.h>
3 #endif
4 #ifndef WIN32
5 #include <sys/time.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8 #else
9 #include <time.h>
10 #endif
11 #include <string.h>
13 #ifdef HAVE_SYS_SELECT_H
14 #include <sys/select.h>
15 #endif
16 #include "cfg.h"
18 /* gets current time in microseconds */
19 unsigned long_long get_time(void)
21 #ifndef WIN32
22 struct timeval tv;
23 struct timezone tz;
25 memset(&tz,0,sizeof(tz));
26 gettimeofday(&tv,&tz);
27 return ((unsigned long_long)tv.tv_sec)*1000000+(unsigned long_long)tv.tv_usec;
28 #else
29 return ((unsigned long_long)GetTickCount())*1000UL;
30 #endif
34 /* waits until time t passes */
35 void sleep_until(unsigned long_long t)
37 unsigned long_long u=get_time();
40 if (u>=t) return;
41 t-=u;
42 #ifdef WIN32
43 Sleep((DWORD)(t/1000));
44 #elif defined(__EMX__)
45 _sleep2(t/1000);
46 #else
48 struct timeval tv;
50 tv.tv_sec=0;
51 tv.tv_usec=t;
52 select(0,NULL,NULL,NULL,&tv);
54 #endif
58 /* waits time t microseconds */
59 void my_sleep(unsigned long_long t)
61 #ifdef WIN32
62 Sleep((DWORD)(t/1000));
63 #elif defined(__EMX__)
64 _sleep2(t/1000);
65 #else
67 struct timeval tv;
69 tv.tv_sec=0;
70 tv.tv_usec=t;
71 select(0,NULL,NULL,NULL,&tv);
73 #endif