Skip to content

getfilesystemtime might cause alignment faults on 64-bit Windows. #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions win32/time.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*****************************************************************************
* *
* DH_TIME.C *
Expand Down Expand Up @@ -33,19 +32,31 @@
#include <errno.h>
#include "php_win32_globals.h"


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);
/*
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/zh-cn/library/ms724284%28v=vs.85%29.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;
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refer CODING_STANDARD.

your code need to be cleaned.
This line-break seems useless and there should be space before and after '=' .

after cleanup you could rebase this commit to one commit. a test file needed too.



PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
Expand Down