--- a/UnixOperatingSystem.st Sat Jul 29 11:03:43 2000 +0200
+++ b/UnixOperatingSystem.st Sun Jul 30 16:41:58 2000 +0200
@@ -7842,100 +7842,15 @@
or use instances of Time, Date or AbsoluteTime to work with.
"
- |seconds millis|
-
-%{
-
- long t;
-
-#if !defined(HAS_GETTIMEOFDAY)
-# if defined(HAS_FTIME)
- struct timeb timebuffer;
-
- ftime(&timebuffer);
- seconds = __MKUINT(timebuffer.time);
- millis = __MKUINT(timebuffer.millitm);
-# define HAVE_TIME
-# endif
-
-# ifndef HAVE_TIME
-# if defined(SYSV) && defined(HZ)
- /*
- * sys5 time; we have to fake the information
- * the returned value is inexact.
- */
- int now;
- long ticks;
- struct tms tb;
-
- now = time(0); /* seconds since 1970 ... */
- seconds = __MKUINT(now);
-
- ticks = times(&tb);
- t = (ticks * 1000) / HZ;
- t = t % 1000;
- millis = __MKSMALLINT(t);
-# endif /* OLD SYSV stuff */
-# endif
-#endif
-
-#ifndef HAVE_TIME
- /* assume HAS_GETTIMEOFDAY
- * - will result in a linkage error
- * if not fixed.
- */
- /*
- * bsd time
- */
- struct timeval tb;
- struct timezone tzb;
-
- gettimeofday(&tb, &tzb);
-
- /*
- * mhmh long-long stuff seems not to work correctly
- * on all machines (sparc)
- * being conservative here ...
- */
-
-# if defined(__GNUC__) && (__GNUC__ >= 2) && defined(i386) && defined(LINUX)
-# define HAS_LONGLONG
-# endif
-
-# ifdef HAS_LONGLONG
- {
- unsigned long long _secs, _millis, rslt;
- unsigned low, hi;
-
- _secs = tb.tv_sec;
- _millis = tb.tv_usec / 1000;
- rslt = _secs * 1000 + _millis;
- low = rslt & 0xFFFFFFFF;
- hi = rslt >> 32;
- RETURN (__MKLARGEINT64(1, low, hi));
- }
-# endif /* long long */
-
-# ifdef alpha64
- {
- unsigned INT _secs, _millis, rslt;
-
- _secs = (INT) tb.tv_sec;
- _millis = (INT) tb.tv_usec / 1000;
- rslt = _secs * 1000 + _millis;
- RETURN (__MKUINT(rslt));
- }
-# endif /* alpha64 */
-
- seconds = __MKUINT(tb.tv_sec);
- millis = __MKUINT(tb.tv_usec / 1000);
-
-#endif
-
-#undef HAVE_TIME
-
-%}.
- ^ (seconds * 1000) + millis
+ |time seconds millis|
+
+ time := self primGetOSTime.
+ time isArray ifTrue:[
+ seconds := time at:1.
+ millis := time at:2.
+ time := (seconds * 1000) + millis
+ ].
+ ^ time
"
OperatingSystem getOSTime printCR.
@@ -7970,6 +7885,126 @@
"Modified: / 5.6.1998 / 18:42:17 / cg"
!
+primGetOSTime
+ "This returns the OS time.
+ The base of the returned value is not consistent across
+ different OS's - some return the number of millis since jan, 1st 1970;
+ others since 1900. The Time classes are prepared for this, and
+ converts as appropriate (by using my fromOSTime: conversion methods).
+
+ Dont use this method in application code since it is an internal (private)
+ interface. For compatibility with ST-80, use Time>>millisecondClockValue.
+ or use instances of Time, Date or AbsoluteTime to work with.
+ "
+
+ |seconds millis|
+
+%{
+
+ long t;
+ long _secs, _millis;
+
+#if !defined(HAS_GETTIMEOFDAY)
+# if defined(HAS_FTIME)
+ {
+ struct timeb timebuffer;
+
+ ftime(&timebuffer);
+ _secs = timebuffer.time;
+ _millis = timebuffer.millitm;
+ }
+# define HAVE_TIME
+# endif /* HAS_FTIME */
+
+# ifndef HAVE_TIME
+# if defined(SYSV) && defined(HZ)
+ {
+ /*
+ * sys5 time; we have to fake the information
+ * the returned value is inexact.
+ */
+ long ticks;
+ struct tms tb;
+
+ _secs = time(0); /* seconds since 1970 ... */
+
+ ticks = times(&tb);
+ t = (ticks * 1000) / HZ;
+ t = t % 1000;
+ _millis = __MKSMALLINT(t);
+ }
+# define HAVE_TIME
+# endif /* OLD SYSV stuff */
+# endif
+#endif /* no HAS_GETTIMEOFDAY */
+
+#ifndef HAVE_TIME
+ /*
+ * use HAS_GETTIMEOFDAY even if HAS_GETTIMEOFDAY is undefined here.
+ * Will result in a linkage error if not fixed and neither ftime() nor time() is used.
+ */
+
+ {
+ /*
+ * bsd time
+ */
+ struct timeval tb;
+ struct timezone tzb;
+
+ gettimeofday(&tb, &tzb);
+
+ _secs = tb.tv_sec;
+ _millis = tb.tv_usec / 1000;
+ }
+#endif
+
+ /*
+ * mhmh long-long stuff seems not to work correctly
+ * on all machines (sparc)
+ * being conservative here ...
+ */
+
+#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(i386) && defined(LINUX)
+# define HAS_LONGLONG
+#endif
+
+#ifdef alpha64
+ {
+ unsigned INT _lsecs, _lmillis, rslt;
+
+ _lsecs = (INT)_secs;
+ _lmillis = (INT)_millis;
+ rslt = _lsecs * 1000 + _lmillis;
+ RETURN (__MKUINT(rslt));
+ }
+#else
+# ifdef HAS_LONGLONG
+ {
+ unsigned long long _lsecs, _lmillis, rslt;
+ unsigned low, hi;
+
+ _lsecs = (long long)_secs;
+ _lmillis = (long long)_millis;
+ rslt = _lsecs * 1000 + _lmillis;
+ low = rslt & 0xFFFFFFFF;
+ hi = rslt >> 32;
+ RETURN (__MKLARGEINT64(1, low, hi));
+ }
+# else
+ seconds = __MKUINT(_secs);
+ millis = __MKUINT(_millis);
+ RETURN (__ARRAY_WITH2(seconds, millis));
+# endif /* long long */
+#endif /* alpha64 */
+%}.
+
+ "
+ OperatingSystem primGetOSTime printCR.
+ Delay waitForSeconds:0.2.
+ OperatingSystem primGetOSTime printCR.
+ "
+!
+
sleep:numberOfSeconds
"{ Pragma: +optSpace }"
@@ -8977,6 +9012,6 @@
!UnixOperatingSystem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.89 2000-07-26 21:13:34 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.90 2000-07-30 14:41:58 cg Exp $'
! !
UnixOperatingSystem initialize!