summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorslayercat <llz916148@yahoo.com.cn>2012-05-23 12:30:16 (GMT)
committerXinchen Hui <laruence@php.net>2012-06-07 06:28:05 (GMT)
commitd9810af45ae9e3cbd2c97543b5dfa2d7c93e81c1 (patch)
tree2c482f8d2c52eaf9d664c6176ec491020b85e2bc /win32
parentc1ac3252288c2eeb0b9278458ad15e19912a945a (diff)
downloadphp-d9810af45ae9e3cbd2c97543b5dfa2d7c93e81c1.tar.gz
based on microsoft's description,the direct convert from FILETIME struct to __int64 is unsafe.
via http://technet.microsoft.com/en-us/library/ms724284(v=vs.85).aspx "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."
Diffstat (limited to 'win32')
-rw-r--r--win32/time.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/win32/time.c b/win32/time.c
index a376fd6..8b847b0 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -1,4 +1,3 @@
-
/*****************************************************************************
* *
* DH_TIME.C *
@@ -37,10 +36,21 @@ int getfilesystemtime(struct timeval *time_Info)
{
FILETIME ft;
__int64 ff;
+ULARGE_INTEGER convFromft;
GetSystemTimeAsFileTime(&ft); /* 100 ns blocks since 01-Jan-1641 */
/* resolution seems to be 0.01 sec */
- ff = *(__int64*)(&ft);
+ /* ff = *(__int64*)(&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
+ */
+ convFromft.HighPart = ft.dwHighDateTime;
+ convFromft.LowPart = ft.dwLowDateTime;
+ ff = convFromft.QuadPart;
+
time_Info->tv_sec = (int)(ff/(__int64)10000000-(__int64)11644473600);
time_Info->tv_usec = (int)(ff % 10000000)/10;
return 0;