summaryrefslogtreecommitdiff
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2002-11-06 13:06:49 -0500
committerAndy Cedilnik <andy.cedilnik@kitware.com>2002-11-06 13:06:49 -0500
commitd7ee016535a12737b9abb41e4032a6a5ab85b095 (patch)
tree0bccce88590c6fb008b186526d67be38ab09beb1 /Source/cmSystemTools.cxx
parent3d4a2fdc52fa01353653afc8835653559f14e10b (diff)
downloadcmake-d7ee016535a12737b9abb41e4032a6a5ab85b095.tar.gz
Move the hi-res time to system tools
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx55
1 files changed, 55 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 1a81a1874b..3a6c362946 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -70,6 +70,61 @@ inline int Chdir(const char* dir)
}
#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__ )
+# include <sys/time.h>
+# define HAVE_GETTIMEOFDAY
+#endif
+
+double
+cmSystemTools::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)
+ return (double)t.tv_sec + t.tv_usec*0.000001;
+#else /* !GETTIMEOFDAY_NO_TZ */
+ if (gettimeofday(&t, (struct timezone *)NULL) == 0)
+ return (double)t.tv_sec + t.tv_usec*0.000001;
+#endif /* !GETTIMEOFDAY_NO_TZ */
+ }
+#endif /* !HAVE_GETTIMEOFDAY */
+ {
+#if defined(HAVE_FTIME)
+ struct TIMEB t;
+ FTIME(&t);
+ return (double)t.time + (double)t.millitm * (double)0.001;
+#else /* !HAVE_FTIME */
+ time_t secs;
+ time(&secs);
+ return (double)secs;
+#endif /* !HAVE_FTIME */
+ }
+}
+
bool cmSystemTools::s_DisableRunCommandOutput = false;
bool cmSystemTools::s_ErrorOccured = false;
bool cmSystemTools::s_DisableMessages = false;