--- boost/date_time/filetime_functions.hpp Wed Feb 27 23:00:24 2008 +++ boost/date_time/filetime_functions.hpp Thu Oct 09 07:44:36 2008 @@ -17,7 +17,16 @@ #include #if defined(BOOST_HAS_FTIME) // skip this file if no FILETIME -#include + +# if defined( BOOST_USE_WINDOWS_H ) +# include +# else + +struct _FILETIME; +typedef struct _FILETIME FILETIME; + +# endif // !BOOST_USE_WINDOWS_H + #include #include @@ -45,9 +54,9 @@ const uint64_t OFFSET = (c1 << 32) + c2; const long sec_pr_day = 86400; // seconds per day - uint64_t filetime = ft.dwHighDateTime; - filetime <<= 32; - filetime += ft.dwLowDateTime; + uint64_t filetime = *reinterpret_cast(&ft); + //filetime <<= 32; + //filetime += ft.dwLowDateTime; filetime -= OFFSET; // filetime is now 100-nanos since 1970-Jan-01 uint64_t sec = filetime / 10000000; --- boost/date_time/microsec_time_clock.hpp Wed Feb 27 23:00:24 2008 +++ boost/date_time/microsec_time_clock.hpp Thu Oct 09 07:59:44 2008 @@ -21,8 +21,44 @@ #include "boost/shared_ptr.hpp" #ifdef BOOST_HAS_FTIME -#include -#endif +# if defined( BOOST_USE_WINDOWS_H ) +# include +# else + +struct _FILETIME; +struct _SYSTEMTIME; + +typedef struct _FILETIME FILETIME; + +typedef struct _FILETIME *PFILETIME; + +typedef struct _FILETIME *LPFILETIME; + +typedef struct _SYSTEMTIME SYSTEMTIME; + +typedef struct _SYSTEMTIME *PSYSTEMTIME; + +typedef struct _SYSTEMTIME *LPSYSTEMTIME; + +extern "C" __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime( + LPFILETIME lpSystemTimeAsFileTime + ); + +extern "C" __declspec(dllimport) int __stdcall FileTimeToLocalFileTime( + const FILETIME *lpFileTime, + LPFILETIME lpLocalFileTime + ); + +extern "C" __declspec(dllimport) void __stdcall GetSystemTime( + LPSYSTEMTIME lpSystemTime + ); + +extern "C" __declspec(dllimport) int __stdcall SystemTimeToFileTime( + const SYSTEMTIME *lpSystemTime, + LPFILETIME lpFileTime + ); +# endif // !BOOST_USE_WINDOWS_H +#endif //BOOST_HAS_FTIME #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK @@ -66,7 +102,7 @@ private: // we want this enum available for both platforms yet still private enum TZ_FOR_CREATE { LOCAL, GMT }; - + public: #ifdef BOOST_HAS_GETTIMEOFDAY @@ -82,7 +118,7 @@ } private: - static time_type create_time(TZ_FOR_CREATE tz) { + static time_type create_time(TZ_FOR_CREATE tz) { timeval tv; gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux. std::time_t t = tv.tv_sec; @@ -114,51 +150,72 @@ #ifdef BOOST_HAS_FTIME //! Return the local time based on computer clock settings static time_type local_time() { - FILETIME ft; + FAKE_FILETIME ft; #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) // Some runtime library implementations expect local times as the norm for ctime. - FILETIME ft_utc; - GetSystemTimeAsFileTime(&ft_utc); - FileTimeToLocalFileTime(&ft_utc,&ft); + FAKE_FILETIME ft_utc; + GetSystemTimeAsFileTime( reinterpret_cast(&ft_utc) ); + FileTimeToLocalFileTime( reinterpret_cast(&ft_utc), reinterpret_cast(&ft) ); #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME) - SYSTEMTIME st; + FAKE_SYSTEMTIME st; GetSystemTime( &st ); - SystemTimeToFileTime( &st, &ft ); + SystemTimeToFileTime( reinterpret_cast(&st), reinterpret_cast(&ft) ); #else - GetSystemTimeAsFileTime(&ft); + GetSystemTimeAsFileTime( reinterpret_cast(&ft) ); #endif - return create_time(ft, LOCAL); + return create_time( reinterpret_cast(ft), LOCAL); } //! Return the UTC time based on computer settings static time_type universal_time() { - FILETIME ft; + FAKE_FILETIME ft; #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) // Some runtime library implementations expect local times as the norm for ctime. - FILETIME ft_utc; - GetSystemTimeAsFileTime(&ft_utc); - FileTimeToLocalFileTime(&ft_utc,&ft); + FAKE_FILETIME ft_utc; + GetSystemTimeAsFileTime( reinterpret_cast(&ft_utc) ); + FileTimeToLocalFileTime( reinterpret_cast(&ft_utc), reinterpret_cast(&ft) ); #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME) - SYSTEMTIME st; - GetSystemTime( &st ); - SystemTimeToFileTime( &st, &ft ); + FAKE_SYSTEMTIME st; + GetSystemTime( reinterpret_cast(&st) ); + SystemTimeToFileTime( reinterpret_cast(&st), reinterpret_cast(&ft) ); #else - GetSystemTimeAsFileTime(&ft); + GetSystemTimeAsFileTime( reinterpret_cast(&ft) ); #endif - return create_time(ft, GMT); + return create_time( reinterpret_cast(ft), GMT); } private: - static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) { +#if defined( BOOST_USE_WINDOWS_H ) + typedef FILETIME FAKE_FILETIME; + typedef SYSTEMTIME FAKE_SYSTEMTIME; +#else + struct FAKE_FILETIME { + unsigned long dwLowDateTime; + unsigned long dwHighDateTime; + }; + + struct FAKE_SYSTEMTIME { + unsigned short wYear; + unsigned short wMonth; + unsigned short wDayOfWeek; + unsigned short wDay; + unsigned short wHour; + unsigned short wMinute; + unsigned short wSecond; + unsigned short wMilliseconds; + }; +#endif + + static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) { // offset is difference (in 100-nanoseconds) from // 1970-Jan-01 to 1601-Jan-01 boost::uint64_t c1 = 27111902; boost::uint64_t c2 = 3577643008UL; // 'UL' removes compiler warnings const boost::uint64_t OFFSET = (c1 << 32) + c2; - boost::uint64_t filetime = ft.dwHighDateTime; - filetime = filetime << 32; - filetime += ft.dwLowDateTime; + boost::uint64_t filetime = *reinterpret_cast(&ft); + //filetime = filetime << 32; + //filetime += ft.dwLowDateTime; filetime -= OFFSET; // filetime now holds 100-nanoseconds since 1970-Jan-01 --- libs/date_time/test/posix_time/testmicrosec_time_clock.cpp Wed Feb 27 23:00:24 2008 +++ libs/date_time/test/posix_time/testmicrosec_time_clock.cpp Thu Oct 09 08:04:14 2008 @@ -9,6 +9,10 @@ #include "boost/date_time/microsec_time_clock.hpp" #include "boost/date_time/testfrmwk.hpp" +//For SYSTEMTIME and GetSystemTime definitions +#if defined(BOOST_HAS_FTIME) +# include +#endif int main()