- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathtime.c
88 lines (75 loc) · 2.61 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*****************************************************************************
* *
* DH_TIME.C *
* *
* Freely redistributable and modifiable. Use at your own risk. *
* *
* Copyright 1994 The Downhill Project *
*
* Modified by Shane Caraveo for use with PHP
*
*****************************************************************************/
/* Include stuff ************************************************************ */
#include<config.w32.h>
#include"time.h"
#include"unistd.h"
#include"signal.h"
#include<windows.h>
#include<winbase.h>
#include<mmsystem.h>
#include<errno.h>
#include"php_win32_globals.h"
staticzend_always_inlinevoidgetfilesystemtime(structtimeval*tv)
{/*{{{*/
FILETIMEft;
unsigned __int64ff=0;
ULARGE_INTEGERfft;
GetSystemTimePreciseAsFileTime(&ft);
/*
* Do not cast a pointer to a FILETIME structure to either a
* ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows.
* via http://technet.microsoft.com/en-us/library/ms724284(v=vs.85).aspx
*/
fft.HighPart=ft.dwHighDateTime;
fft.LowPart=ft.dwLowDateTime;
ff=fft.QuadPart;
ff /= 10Ui64; /* convert to microseconds */
ff-=11644473600000000Ui64; /* convert to unix epoch */
tv->tv_sec= (long)(ff / 1000000Ui64);
tv->tv_usec= (long)(ff % 1000000Ui64);
}/*}}}*/
PHPAPIintgettimeofday(structtimeval*time_Info, structtimezone*timezone_Info)
{/*{{{*/
/* Get the time, if they want it */
if (time_Info!=NULL) {
getfilesystemtime(time_Info);
}
/* Get the timezone, if they want it */
if (timezone_Info!=NULL) {
_tzset();
timezone_Info->tz_minuteswest=_timezone;
timezone_Info->tz_dsttime=_daylight;
}
/* And return */
return0;
}/*}}}*/
PHPAPIintusleep(unsigned intuseconds)
{/*{{{*/
HANDLEtimer;
LARGE_INTEGERdue;
due.QuadPart=-(10* (__int64)useconds);
timer=CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
return0;
}/*}}}*/
PHPAPIintnanosleep( conststructtimespec*rqtp, structtimespec*rmtp )
{/*{{{*/
if (rqtp->tv_nsec>999999999) {
/* The time interval specified 1,000,000 or more microseconds. */
errno=EINVAL;
return-1;
}
returnusleep( rqtp->tv_sec*1000000+rqtp->tv_nsec / 1000 );
}/*}}}*/