forked from caidongyun/beanstalkd-win
-
Notifications
You must be signed in to change notification settings - Fork 6
/
time.c
44 lines (36 loc) · 853 Bytes
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdint.h>
#include <stdlib.h>
#include "dat.h"
#ifndef WIN32
# include <sys/time.h>
#else
#include "dat_w32.h"
#include <time.h>
int gettimeofday(struct timeval *tp, void *tzp)
{
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm. tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
return (0);
}
#endif
int64
nanoseconds(void)
{
int r;
struct timeval tv;
r = gettimeofday(&tv, 0);
if (r != 0) return warnx("gettimeofday"), -1; // can't happen
return ((int64)tv.tv_sec)*1000000000 + ((int64)tv.tv_usec)*1000;
}