1999-04-08 05:05:13 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
* *
|
|
|
|
* DH_TIME.C *
|
|
|
|
* *
|
|
|
|
* Freely redistributable and modifiable. Use at your own risk. *
|
|
|
|
* *
|
|
|
|
* Copyright 1994 The Downhill Project *
|
2015-01-03 17:22:58 +08:00
|
|
|
*
|
1999-04-08 05:05:13 +08:00
|
|
|
* Modified by Shane Caraveo for use with PHP
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* Include stuff ************************************************************ */
|
1999-04-24 04:06:01 +08:00
|
|
|
|
2008-08-15 07:29:25 +08:00
|
|
|
#include <config.w32.h>
|
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
#include "time.h"
|
|
|
|
#include "unistd.h"
|
|
|
|
#include "signal.h"
|
2003-11-30 06:59:33 +08:00
|
|
|
#include <windows.h>
|
1999-04-08 05:05:13 +08:00
|
|
|
#include <winbase.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#include <errno.h>
|
2004-07-29 10:59:44 +08:00
|
|
|
#include "php_win32_globals.h"
|
1999-04-08 05:05:13 +08:00
|
|
|
|
2013-03-16 02:04:40 +08:00
|
|
|
typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
|
|
|
|
|
2014-12-23 19:02:36 +08:00
|
|
|
static MyGetSystemTimeAsFileTime timefunc = NULL;
|
|
|
|
|
2015-06-02 03:52:35 +08:00
|
|
|
#ifdef PHP_EXPORTS
|
2014-12-23 19:02:36 +08:00
|
|
|
static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void)
|
2017-07-04 22:08:48 +08:00
|
|
|
{/*{{{*/
|
2013-03-16 02:04:40 +08:00
|
|
|
MyGetSystemTimeAsFileTime timefunc = NULL;
|
2015-06-02 03:52:35 +08:00
|
|
|
HMODULE hMod = GetModuleHandle("kernel32.dll");
|
2013-03-16 02:04:40 +08:00
|
|
|
|
|
|
|
if (hMod) {
|
|
|
|
/* Max possible resolution <1us, win8/server2012 */
|
|
|
|
timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime");
|
2016-08-11 10:13:34 +08:00
|
|
|
}
|
2013-03-16 02:04:40 +08:00
|
|
|
|
Get rid of these slow calls to LoadLibrary()/GetProcAddress() calls on Windows, we require Windows Vista as bare minimum for PHP anyway, so it does not make any sense to do this slow emulation anyway.
GD:
- PrintWindow() is available as of Windows XP, it requires linking to User32.lib, which config.w32 for ext/gd already.
CLI:
- The borrowed functions from PostgreSQL to set the titles of the console window uses SetConsoleTitle() and GetConsoleTitle(), both are available as of Windows 2000 from Kernel32.lib which we already are linking against.
Standard:
- The disk space utility functions uses GetDiskFreeSpaceExA() which is available as of Windows XP, again links to Kernel32.lib.
- The symlink() PHP function uses CreateSymbolicLinkA() which is available from Windows Vista, again from Kernel32.lib.
- php_get_windows_name() in info.c uses GetNativeSystemInfo() which is available as of Windows XP and GetProductInfo() which is available as of Windows Vista, both are again from Kernel32.lib.
Notes:
- ext/interbase & ext/pdo_firebird uses GetProcAddress(), I'm not entirely sure how to handle this one.
- ext/sqlite3, this is apart of the bundled libsqlite3, I don't really wanna play around with our bundled libs and make it a bigger issue for those who maintain and upgrade them.
- ext/readline, the call to GetProcAddress() here does not do any system calls, so it is left as is.
- win32/ioutil.c uses GetProcAddress(), but the function it attempts to load (PathCchCanonicalizeEx()) is only available from Windows 8 and greater (Pathcch.lib linkage).
- win32/time.c uses GetSystemTimePreciseAsFileTime() which is available from Windows 8 and greater to get the current system date and time which the highest possible precision and falls back to GetSystemTimeAsFileTime() (available as of Windows 2000), again Kernel32.lib, the GetSystemTimePreciseAsFileTime() is left in a GetProcAddress().
2016-08-11 08:09:50 +08:00
|
|
|
if(!timefunc) {
|
|
|
|
/* 100ns blocks since 01-Jan-1641 */
|
|
|
|
timefunc = (MyGetSystemTimeAsFileTime) GetSystemTimeAsFileTime;
|
2013-03-16 02:04:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return timefunc;
|
2017-07-04 22:08:48 +08:00
|
|
|
}/*}}}*/
|
2001-02-04 23:52:32 +08:00
|
|
|
|
2016-08-11 10:35:51 +08:00
|
|
|
void php_win32_init_gettimeofday(void)
|
2017-07-04 22:08:48 +08:00
|
|
|
{/*{{{*/
|
2015-06-02 03:52:35 +08:00
|
|
|
timefunc = get_time_func();
|
2017-07-04 22:08:48 +08:00
|
|
|
}/*}}}*/
|
2015-06-02 03:52:35 +08:00
|
|
|
#endif
|
|
|
|
|
2014-12-23 19:02:36 +08:00
|
|
|
static zend_always_inline int getfilesystemtime(struct timeval *tv)
|
2017-07-04 22:08:48 +08:00
|
|
|
{/*{{{*/
|
2013-03-16 02:04:40 +08:00
|
|
|
FILETIME ft;
|
|
|
|
unsigned __int64 ff = 0;
|
2013-03-24 00:40:06 +08:00
|
|
|
ULARGE_INTEGER fft;
|
2013-03-16 02:04:40 +08:00
|
|
|
|
2014-12-23 19:02:36 +08:00
|
|
|
timefunc(&ft);
|
2013-03-16 02:04:40 +08:00
|
|
|
|
2013-03-24 00:40:06 +08:00
|
|
|
/*
|
2015-01-03 17:22:58 +08:00
|
|
|
* Do not cast a pointer to a FILETIME structure to either a
|
2013-03-24 00:40:06 +08:00
|
|
|
* 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 */
|
2013-03-16 02:04:40 +08:00
|
|
|
ff -= 11644473600000000Ui64; /* convert to unix epoch */
|
|
|
|
|
2013-03-24 00:40:06 +08:00
|
|
|
tv->tv_sec = (long)(ff / 1000000Ui64);
|
|
|
|
tv->tv_usec = (long)(ff % 1000000Ui64);
|
2013-03-16 02:04:40 +08:00
|
|
|
|
|
|
|
return 0;
|
2017-07-04 22:08:48 +08:00
|
|
|
}/*}}}*/
|
2001-02-04 23:52:32 +08:00
|
|
|
|
2002-06-24 07:22:33 +08:00
|
|
|
PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
|
2017-07-04 22:08:48 +08:00
|
|
|
{/*{{{*/
|
1999-04-08 05:05:13 +08:00
|
|
|
/* Get the time, if they want it */
|
|
|
|
if (time_Info != NULL) {
|
2013-03-16 02:04:40 +08:00
|
|
|
getfilesystemtime(time_Info);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
/* Get the timezone, if they want it */
|
|
|
|
if (timezone_Info != NULL) {
|
|
|
|
_tzset();
|
|
|
|
timezone_Info->tz_minuteswest = _timezone;
|
|
|
|
timezone_Info->tz_dsttime = _daylight;
|
|
|
|
}
|
|
|
|
/* And return */
|
|
|
|
return 0;
|
2017-07-04 22:08:48 +08:00
|
|
|
}/*}}}*/
|
1999-04-08 05:05:13 +08:00
|
|
|
|
2009-01-19 10:35:22 +08:00
|
|
|
PHPAPI int usleep(unsigned int useconds)
|
2017-07-04 22:08:48 +08:00
|
|
|
{/*{{{*/
|
2003-11-30 06:48:42 +08:00
|
|
|
HANDLE timer;
|
|
|
|
LARGE_INTEGER due;
|
|
|
|
|
2004-01-13 10:07:04 +08:00
|
|
|
due.QuadPart = -(10 * (__int64)useconds);
|
1999-04-08 05:05:13 +08:00
|
|
|
|
2004-01-13 10:07:04 +08:00
|
|
|
timer = CreateWaitableTimer(NULL, TRUE, NULL);
|
2003-11-30 06:48:42 +08:00
|
|
|
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
|
|
|
|
WaitForSingleObject(timer, INFINITE);
|
|
|
|
CloseHandle(timer);
|
2009-01-19 10:35:22 +08:00
|
|
|
return 0;
|
2017-07-04 22:08:48 +08:00
|
|
|
}/*}}}*/
|
2009-01-19 10:35:22 +08:00
|
|
|
|
|
|
|
PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
|
2017-07-04 22:08:48 +08:00
|
|
|
{/*{{{*/
|
2009-01-19 10:35:22 +08:00
|
|
|
if (rqtp->tv_nsec > 999999999) {
|
|
|
|
/* The time interval specified 1,000,000 or more microseconds. */
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 );
|
2017-07-04 22:08:48 +08:00
|
|
|
}/*}}}*/
|
1999-04-08 05:05:13 +08:00
|
|
|
|
2015-05-21 00:51:19 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
|
|
|
*/
|