php-src/win32/time.c

89 lines
2.6 KiB
C
Raw Normal View History

1999-04-07 21:05:13 +00:00
/*****************************************************************************
* *
* DH_TIME.C *
* *
* Freely redistributable and modifiable. Use at your own risk. *
* *
* Copyright 1994 The Downhill Project *
2015-01-03 09:22:58 +00:00
*
1999-04-07 21:05:13 +00:00
* Modified by Shane Caraveo for use with PHP
*
*****************************************************************************/
/* Include stuff ************************************************************ */
1999-04-23 20:06:01 +00:00
#include <config.w32.h>
1999-04-07 21:05:13 +00:00
#include "time.h"
#include "unistd.h"
#include "signal.h"
#include <windows.h>
1999-04-07 21:05:13 +00:00
#include <winbase.h>
#include <mmsystem.h>
#include <errno.h>
2004-07-29 02:59:44 +00:00
#include "php_win32_globals.h"
1999-04-07 21:05:13 +00:00
static zend_always_inline void getfilesystemtime(struct timeval *tv)
2017-07-04 14:08:48 +00:00
{/*{{{*/
2013-03-15 18:04:40 +00:00
FILETIME ft;
unsigned __int64 ff = 0;
ULARGE_INTEGER fft;
2013-03-15 18:04:40 +00:00
GetSystemTimePreciseAsFileTime(&ft);
2013-03-15 18:04:40 +00:00
/*
2015-01-03 09:22:58 +00:00
* 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 */
2013-03-15 18:04:40 +00:00
ff -= 11644473600000000Ui64; /* convert to unix epoch */
tv->tv_sec = (long)(ff / 1000000Ui64);
tv->tv_usec = (long)(ff % 1000000Ui64);
2017-07-04 14:08:48 +00:00
}/*}}}*/
PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
2017-07-04 14:08:48 +00:00
{/*{{{*/
1999-04-07 21:05:13 +00:00
/* Get the time, if they want it */
if (time_Info != NULL) {
2013-03-15 18:04:40 +00:00
getfilesystemtime(time_Info);
1999-04-07 21:05:13 +00: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 14:08:48 +00:00
}/*}}}*/
1999-04-07 21:05:13 +00:00
PHPAPI int usleep(unsigned int useconds)
2017-07-04 14:08:48 +00:00
{/*{{{*/
2003-11-29 22:48:42 +00:00
HANDLE timer;
LARGE_INTEGER due;
2004-01-13 02:07:04 +00:00
due.QuadPart = -(10 * (__int64)useconds);
1999-04-07 21:05:13 +00:00
2004-01-13 02:07:04 +00:00
timer = CreateWaitableTimer(NULL, TRUE, NULL);
2003-11-29 22:48:42 +00:00
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
return 0;
2017-07-04 14:08:48 +00:00
}/*}}}*/
PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
2017-07-04 14:08:48 +00: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 14:08:48 +00:00
}/*}}}*/