diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index eefa7f587..d1f159174 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -56,6 +56,7 @@ // support for realpath call #ifndef _WIN32 +#include #include #include #include @@ -281,71 +282,29 @@ extern int putenv (char *__string) __THROW; } #endif -/* Implement floattime() for various platforms */ -// Taken from Python 2.1.3 - -#if defined( _WIN32 ) && !defined( __CYGWIN__ ) -# include -# define HAVE_FTIME -# if defined( __BORLANDC__) -# define FTIME ftime -# define TIMEB timeb -# else // Visual studio? -# define FTIME _ftime -# define TIMEB _timeb -# endif -#elif defined( __CYGWIN__ ) || defined( __linux__ ) || defined(__APPLE__) -# include -# include -# define HAVE_GETTIMEOFDAY -#endif - namespace KWSYS_NAMESPACE { +double SystemTools::GetTime(void) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + return (429.4967296*ft.dwHighDateTime + + 0.0000001*ft.dwLowDateTime + - 11644473600.0); +#else + struct timeval t; + gettimeofday(&t, 0); + return 1.0*t.tv_sec + 0.000001*t.tv_usec; +#endif +} + class SystemToolsTranslationMap : public kwsys_stl::map { }; - -double -SystemTools::GetTime(void) -{ - /* There are three ways to get the time: - (1) gettimeofday() -- resolution in microseconds - (2) ftime() -- resolution in milliseconds - (3) time() -- resolution in seconds - In all cases the return value is a float in seconds. - Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may - fail, so we fall back on ftime() or time(). - Note: clock resolution does not imply clock accuracy! */ -#ifdef HAVE_GETTIMEOFDAY - { - struct timeval t; -#ifdef GETTIMEOFDAY_NO_TZ - if (gettimeofday(&t) == 0) -#else /* !GETTIMEOFDAY_NO_TZ */ - if (gettimeofday(&t, static_cast(NULL)) == 0) -#endif /* !GETTIMEOFDAY_NO_TZ */ - return static_cast(t.tv_sec) + - static_cast(t.tv_usec)*0.000001; - } -#endif /* !HAVE_GETTIMEOFDAY */ - { -#if defined(HAVE_FTIME) - struct TIMEB t; - ::FTIME(&t); - return static_cast(t.time) + - static_cast(t.millitm) * static_cast(0.001); -#else /* !HAVE_FTIME */ - time_t secs; - time(&secs); - return static_cast(secs); -#endif /* !HAVE_FTIME */ - } -} - // adds the elements of the env variable path to the arg passed in void SystemTools::GetPath(kwsys_stl::vector& path, const char* env) { diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index cf4792304..fd2ed1971 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -690,13 +690,7 @@ public: * ----------------------------------------------------------------- */ - /** - * Get current time as a double. On certain platforms this will - * return higher resolution than seconds: - * (1) gettimeofday() -- resolution in microseconds - * (2) ftime() -- resolution in milliseconds - * (3) time() -- resolution in seconds - */ + /** Get current time in seconds since Posix Epoch (Jan 1, 1970). */ static double GetTime(); /**