123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #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"
- typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
- static MyGetSystemTimeAsFileTime timefunc = NULL;
- #ifdef PHP_EXPORTS
- static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void)
- {
- MyGetSystemTimeAsFileTime timefunc = NULL;
- HMODULE hMod = GetModuleHandle("kernel32.dll");
- if (hMod) {
-
- timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime");
- }
- if(!timefunc) {
-
- timefunc = (MyGetSystemTimeAsFileTime) GetSystemTimeAsFileTime;
- }
- return timefunc;
- }
- void php_win32_init_gettimeofday(void)
- {
- timefunc = get_time_func();
- }
- #endif
- static zend_always_inline int getfilesystemtime(struct timeval *tv)
- {
- FILETIME ft;
- unsigned __int64 ff = 0;
- ULARGE_INTEGER fft;
- timefunc(&ft);
-
- fft.HighPart = ft.dwHighDateTime;
- fft.LowPart = ft.dwLowDateTime;
- ff = fft.QuadPart;
- ff /= 10Ui64;
- ff -= 11644473600000000Ui64;
- tv->tv_sec = (long)(ff / 1000000Ui64);
- tv->tv_usec = (long)(ff % 1000000Ui64);
- return 0;
- }
- PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
- {
-
- if (time_Info != NULL) {
- getfilesystemtime(time_Info);
- }
-
- if (timezone_Info != NULL) {
- _tzset();
- timezone_Info->tz_minuteswest = _timezone;
- timezone_Info->tz_dsttime = _daylight;
- }
-
- return 0;
- }
- PHPAPI int usleep(unsigned int useconds)
- {
- HANDLE timer;
- LARGE_INTEGER due;
- due.QuadPart = -(10 * (__int64)useconds);
- timer = CreateWaitableTimer(NULL, TRUE, NULL);
- SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
- WaitForSingleObject(timer, INFINITE);
- CloseHandle(timer);
- return 0;
- }
- PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
- {
- if (rqtp->tv_nsec > 999999999) {
-
- errno = EINVAL;
- return -1;
- }
- return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 );
- }
|