summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-08-03 18:48:48 (GMT)
committerBrad King <brad.king@kitware.com>2011-08-03 18:50:04 (GMT)
commit74e1156bc292f45dd376d6324fbf13aa2de539b7 (patch)
treed68a664bba6d649b8c4ae0892b6da3dcb2b84300 /Source/kwsys/SystemTools.cxx
parent14e54c4c449e2704799ab5283c6c6764472d5a0a (diff)
downloadCMake-74e1156bc292f45dd376d6324fbf13aa2de539b7.zip
CMake-74e1156bc292f45dd376d6324fbf13aa2de539b7.tar.gz
CMake-74e1156bc292f45dd376d6324fbf13aa2de539b7.tar.bz2
KWSys: Simplify SystemTools::GetTime implementation (#12261)
We already use GetSystemTimeAsFileTime() and gettimeofday() unconditionally on supported Windows and non-Windows platforms, respectively. Remove outdated portability complexity.
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx73
1 files changed, 16 insertions, 57 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index eefa7f5..d1f1591 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -56,6 +56,7 @@
// support for realpath call
#ifndef _WIN32
+#include <sys/time.h>
#include <utime.h>
#include <limits.h>
#include <sys/wait.h>
@@ -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 <sys/timeb.h>
-# 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 <sys/time.h>
-# include <time.h>
-# 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<kwsys_stl::string,kwsys_stl::string>
{
};
-
-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<struct timezone *>(NULL)) == 0)
-#endif /* !GETTIMEOFDAY_NO_TZ */
- return static_cast<double>(t.tv_sec) +
- static_cast<double>(t.tv_usec)*0.000001;
- }
-#endif /* !HAVE_GETTIMEOFDAY */
- {
-#if defined(HAVE_FTIME)
- struct TIMEB t;
- ::FTIME(&t);
- return static_cast<double>(t.time) +
- static_cast<double>(t.millitm) * static_cast<double>(0.001);
-#else /* !HAVE_FTIME */
- time_t secs;
- time(&secs);
- return static_cast<double>(secs);
-#endif /* !HAVE_FTIME */
- }
-}
-
// adds the elements of the env variable path to the arg passed in
void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char* env)
{