--- a/Unix.st Sun Jun 30 13:02:29 1996 +0200
+++ b/Unix.st Mon Jul 01 15:26:33 1996 +0200
@@ -3717,84 +3717,81 @@
future without affecting existing applications."
|info type mode uid gid size id
- atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi|
+ atime mtime ctime|
%{
struct stat buf;
int ret;
if (__isString(aPathName)) {
- __BEGIN_INTERRUPTABLE__
- do {
- ret = stat((char *) __stringVal(aPathName), &buf);
- } while ((ret < 0) && (errno == EINTR));
- __END_INTERRUPTABLE__
-
- if (ret < 0) {
- @global(LastErrorNumber) = __MKSMALLINT(errno);
- RETURN ( nil );
- }
- switch (buf.st_mode & S_IFMT) {
- case S_IFDIR:
- type = @symbol(directory);
- break;
- case S_IFREG:
- type = @symbol(regular);
- break;
+ __BEGIN_INTERRUPTABLE__
+ do {
+ ret = stat((char *) __stringVal(aPathName), &buf);
+ } while ((ret < 0) && (errno == EINTR));
+ __END_INTERRUPTABLE__
+
+ if (ret < 0) {
+ @global(LastErrorNumber) = __MKSMALLINT(errno);
+ RETURN ( nil );
+ }
+ switch (buf.st_mode & S_IFMT) {
+ case S_IFDIR:
+ type = @symbol(directory);
+ break;
+ case S_IFREG:
+ type = @symbol(regular);
+ break;
#ifdef S_IFCHR
- case S_IFCHR:
- type = @symbol(characterSpecial);
- break;
+ case S_IFCHR:
+ type = @symbol(characterSpecial);
+ break;
#endif
#ifdef S_IFBLK
- case S_IFBLK:
- type = @symbol(blockSpecial);
- break;
+ case S_IFBLK:
+ type = @symbol(blockSpecial);
+ break;
#endif
#ifdef S_IFLNK
- case S_IFLNK:
- type = @symbol(symbolicLink);
- break;
+ case S_IFLNK:
+ type = @symbol(symbolicLink);
+ break;
#endif
#ifdef S_IFSOCK
- case S_IFSOCK:
- type = @symbol(socket);
- break;
+ case S_IFSOCK:
+ type = @symbol(socket);
+ break;
#endif
#ifdef S_IFIFO
- case S_IFIFO:
- type = @symbol(fifo);
- break;
-#endif
- default:
- type = @symbol(unknown);
- break;
- }
- mode = __MKSMALLINT(buf.st_mode & 0777);
- uid = __MKSMALLINT(buf.st_uid);
- gid = __MKSMALLINT(buf.st_gid);
- size = __MKSMALLINT(buf.st_size);
- id = __MKSMALLINT(buf.st_ino);
- atimeLow = __MKSMALLINT(buf.st_atime & 0xFFFF);
- atimeHi = __MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
- mtimeLow = __MKSMALLINT(buf.st_mtime & 0xFFFF);
- mtimeHi = __MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
- ctimeLow = __MKSMALLINT(buf.st_ctime & 0xFFFF);
- ctimeHi = __MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF);
+ case S_IFIFO:
+ type = @symbol(fifo);
+ break;
+#endif
+ default:
+ type = @symbol(unknown);
+ break;
+ }
+ mode = __MKSMALLINT(buf.st_mode & 0777);
+ uid = __MKSMALLINT(buf.st_uid);
+ gid = __MKSMALLINT(buf.st_gid);
+ size = __MKSMALLINT(buf.st_size);
+ id = __MKSMALLINT(buf.st_ino);
+ atime = __MKUINT(buf.st_atime);
+ mtime = __MKUINT(buf.st_mtime);
+ ctime = __MKUINT(buf.st_ctime);
}
%}.
mode notNil ifTrue:[
- info := IdentityDictionary new.
- info at:#type put:type.
- info at:#mode put:mode.
- info at:#uid put:uid.
- info at:#gid put:gid.
- info at:#size put:size.
- info at:#id put:id.
- info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi).
- info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi).
- info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi).
- ^ info
+ info := IdentityDictionary new.
+ info at:#type put:type.
+ info at:#mode put:mode.
+ info at:#uid put:uid.
+ info at:#gid put:gid.
+ info at:#size put:size.
+ info at:#id put:id.
+ info at:#accessed put:(AbsoluteTime fromOSTime:(atime * 1000)).
+ info at:#modified put:(AbsoluteTime fromOSTime:(mtime * 1000)).
+ info at:#statusChanged put:(AbsoluteTime fromOSTime:(ctime * 1000)).
+ ^ info
].
^ self primitiveFailed
@@ -3945,8 +3942,7 @@
on contrast to #infoOf:, which returns the info of the pointed to file
in case of a symbolic link."
- |info type mode uid gid size id atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi
- path|
+ |info type mode uid gid size id atime mtime ctime path|
%{ /* STACK: 1200 */
#ifdef S_IFLNK
@@ -3955,60 +3951,57 @@
char pathBuffer[1024];
if (__isString(aPathName)) {
- __BEGIN_INTERRUPTABLE__
- do {
- ret = lstat((char *) __stringVal(aPathName), &buf);
- } while ((ret < 0) && (errno == EINTR));
- __END_INTERRUPTABLE__
-
- if (ret < 0) {
- @global(LastErrorNumber) = __MKSMALLINT(errno);
- RETURN ( nil );
- }
- switch (buf.st_mode & S_IFMT) {
- default:
- RETURN ( nil ); /* not a symbolic link */
-
- case S_IFLNK:
- type = @symbol(symbolicLink);
- break;
- }
-
- mode = __MKSMALLINT(buf.st_mode & 0777);
- uid = __MKSMALLINT(buf.st_uid);
- gid = __MKSMALLINT(buf.st_gid);
- size = __MKSMALLINT(buf.st_size);
- id = __MKSMALLINT(buf.st_ino);
- atimeLow = __MKSMALLINT(buf.st_atime & 0xFFFF);
- atimeHi = __MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
- mtimeLow = __MKSMALLINT(buf.st_mtime & 0xFFFF);
- mtimeHi = __MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
- ctimeLow = __MKSMALLINT(buf.st_ctime & 0xFFFF);
- ctimeHi = __MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF);
- if ((ret = readlink((char *) __stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) {
- OperatingSystem_LastErrorNumber = __MKSMALLINT(errno);
- RETURN ( nil );
- }
- pathBuffer[ret] = '\0'; /* readlink does not 0-terminate */
- path = __MKSTRING(pathBuffer COMMA_CON);
+ __BEGIN_INTERRUPTABLE__
+ do {
+ ret = lstat((char *) __stringVal(aPathName), &buf);
+ } while ((ret < 0) && (errno == EINTR));
+ __END_INTERRUPTABLE__
+
+ if (ret < 0) {
+ @global(LastErrorNumber) = __MKSMALLINT(errno);
+ RETURN ( nil );
+ }
+ switch (buf.st_mode & S_IFMT) {
+ default:
+ RETURN ( nil ); /* not a symbolic link */
+
+ case S_IFLNK:
+ type = @symbol(symbolicLink);
+ break;
+ }
+
+ mode = __MKSMALLINT(buf.st_mode & 0777);
+ uid = __MKSMALLINT(buf.st_uid);
+ gid = __MKSMALLINT(buf.st_gid);
+ size = __MKSMALLINT(buf.st_size);
+ id = __MKSMALLINT(buf.st_ino);
+ atime = __MKUINT(buf.st_atime);
+ mtime = __MKUINT(buf.st_mtime);
+ ctime = __MKUINT(buf.st_ctime);
+ if ((ret = readlink((char *) __stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) {
+ OperatingSystem_LastErrorNumber = __MKSMALLINT(errno);
+ RETURN ( nil );
+ }
+ pathBuffer[ret] = '\0'; /* readlink does not 0-terminate */
+ path = __MKSTRING(pathBuffer COMMA_CON);
}
#else
RETURN ( nil );
#endif
%}.
mode notNil ifTrue:[
- info := IdentityDictionary new.
- info at:#type put:type.
- info at:#mode put:mode.
- info at:#uid put:uid.
- info at:#gid put:gid.
- info at:#size put:size.
- info at:#id put:id.
- info at:#path put:path.
- info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi).
- info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi).
- info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi).
- ^ info
+ info := IdentityDictionary new.
+ info at:#type put:type.
+ info at:#mode put:mode.
+ info at:#uid put:uid.
+ info at:#gid put:gid.
+ info at:#size put:size.
+ info at:#id put:id.
+ info at:#path put:path.
+ info at:#accessed put:(AbsoluteTime fromOSTime:(atime * 1000)).
+ info at:#modified put:(AbsoluteTime fromOSTime:(mtime * 1000)).
+ info at:#statusChanged put:(AbsoluteTime fromOSTime:(ctime * 1000)).
+ ^ info
].
^ self primitiveFailed
@@ -4112,29 +4105,28 @@
For nonexistent files, nil is returned."
"could be implemented as:
- (self infoOf:aPathName) at:#accessed
- "
- |timeLow timeHi|
+ (self infoOf:aPathName) at:#accessed
+ "
+ |osSeconds|
%{
struct stat buf;
time_t mtime;
int ret;
if (__isString(aPathName)) {
- __BEGIN_INTERRUPTABLE__
- do {
- ret = stat((char *) __stringVal(aPathName), &buf);
- } while (ret < 0 && errno == EINTR);
- __END_INTERRUPTABLE__
- if (ret < 0) {
- OperatingSystem_LastErrorNumber = __MKSMALLINT(errno);
- RETURN (nil);
- }
- timeLow = __MKSMALLINT(buf.st_atime & 0xFFFF);
- timeHi = __MKSMALLINT((buf.st_atime >> 16) & 0xFFFF);
+ __BEGIN_INTERRUPTABLE__
+ do {
+ ret = stat((char *) __stringVal(aPathName), &buf);
+ } while (ret < 0 && errno == EINTR);
+ __END_INTERRUPTABLE__
+ if (ret < 0) {
+ @global(LastErrorNumber) = __MKSMALLINT(errno);
+ RETURN (nil);
+ }
+ osSeconds = __MKUINT(buf.st_atime);
}
%}.
- timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi].
+ osSeconds notNil ifTrue:[^ AbsoluteTime fromOSTime:(osSeconds * 1000)].
^ self primitiveFailed
"
@@ -4147,30 +4139,29 @@
For nonexistent files, nil is returned."
"could be implemented as:
- (self infoOf:aPathName) at:#modified
- "
-
- |timeLow timeHi|
+ (self infoOf:aPathName) at:#modified
+ "
+
+ |osSeconds|
%{
struct stat buf;
int ret;
time_t mtime;
if (__isString(aPathName)) {
- __BEGIN_INTERRUPTABLE__
- do {
- ret = stat((char *) __stringVal(aPathName), &buf);
- } while (ret < 0 && errno == EINTR);
- __END_INTERRUPTABLE__
- if (ret < 0) {
- OperatingSystem_LastErrorNumber = __MKSMALLINT(errno);
- RETURN ( nil );
- }
- timeLow = __MKSMALLINT(buf.st_mtime & 0xFFFF);
- timeHi = __MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF);
+ __BEGIN_INTERRUPTABLE__
+ do {
+ ret = stat((char *) __stringVal(aPathName), &buf);
+ } while (ret < 0 && errno == EINTR);
+ __END_INTERRUPTABLE__
+ if (ret < 0) {
+ @global(LastErrorNumber) = __MKSMALLINT(errno);
+ RETURN ( nil );
+ }
+ osSeconds = __MKUINT(buf.st_mtime);
}
%}.
- timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi].
+ osSeconds notNil ifTrue:[^ AbsoluteTime fromOSTime:(osSeconds * 1000)].
^ self primitiveFailed
"
@@ -6230,55 +6221,82 @@
!OperatingSystem class methodsFor:'time and date'!
-computeDatePartsOf:osTimeLow and:osTimeHi for:aBlock
- "compute year, month and day from the OS time-parts osTimeLow and
- osTimeHi and evaluate the argument, a 3-arg block with these.
- Conversion is to localtime including any daylight saving adjustments.
-
- This method was added to avoid LargeInteger arithmetic and to be
- independent of how the OperatingSystem represents time;
- the time-parts expected are those returned by getTimeParts."
-
- |year month day|
-
- ((osTimeLow isMemberOf:SmallInteger)
- and:[osTimeHi isMemberOf:SmallInteger]) ifFalse:[
- ^ self primitiveFailed
- ].
+computeDatePartsOf:osTime for:aBlock
+ "compute year, month and day from the OS time, osTime
+ and evaluate the argument, a 3-arg block with these.
+ Conversion is to localtime including any daylight saving adjustments."
+
+ |year month day osSeconds|
+
+ osSeconds := osTime // 1000.
%{
struct tm *tmPtr;
long t;
- t = (__intVal(osTimeHi) << 16) | __intVal(osTimeLow);
+ t = __longIntVal(osSeconds);
+
tmPtr = localtime(&t);
year = __MKSMALLINT(tmPtr->tm_year + 1900);
month = __MKSMALLINT(tmPtr->tm_mon + 1);
day = __MKSMALLINT(tmPtr->tm_mday);
%}.
aBlock value:year value:month value:day
-!
-
-computeDatePartsOf:osTimeParts for:aBlock
- "compute year, month and day from the ostime in timeParts,
- and evaluate the argument, a 3-arg block with these.
+
+ "
+ OperatingSystem n_computeDatePartsOf:0 for:[:y :m :d |
+ y printCR. m printCR. d printCR
+ ]
+ "
+!
+
+computeOSTimeFromYear:y month:m day:d hour:h minute:min seconds:s millis:millis
+ "return the OS-dependent time for the given time and day.
+ The arguments are assumed to be in localtime including
+ any daylight saving adjustings."
+
+ |osSeconds|
+
+%{
+ struct tm tm;
+ long t;
+
+ if (__bothSmallInteger(y, m)
+ && __bothSmallInteger(d, h)
+ && __bothSmallInteger(min, s)) {
+ tm.tm_hour = __intVal(h);
+ tm.tm_min = __intVal(min);
+ tm.tm_sec = __intVal(s);
+
+ tm.tm_year = __intVal(y) - 1900;
+ tm.tm_mon = __intVal(m) - 1;
+ tm.tm_mday = __intVal(d);
+ tm.tm_isdst = -1;
+
+ t = mktime(&tm);
+ osSeconds = __MKUINT(t);
+ }
+%}.
+ osSeconds notNil ifTrue:[
+ ^ osSeconds * 1000 + millis
+ ].
+ ^ self primitiveFailed
+
+ "
+ OperatingSystem n_computeOSTimeFromYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
+ "
+
+!
+
+computeTimeAndDateFrom:osTime
+ "given an OS-dependent time in osTime, return an Array
+ containing year, month, day, hour, minute and seconds,
+ offset to UTC, daylight savings time flag and milliseconds.
Conversion is to localtime including any daylight saving adjustments."
- ^ self
- computeDatePartsOf:(osTimeParts at:1)
- and:(osTimeParts at:2)
- for:aBlock
-!
-
-computeTimeAndDateFrom:osTimeParts
- "given an Array containing the OS-dependent time, return an Array
- containing year, month, day, hour, minute and seconds,
- offset to UTC and a daylight savings time flag.
- Conversion is to localtime including any daylight saving adjustments."
-
- |low hi year month day hours minutes seconds utcOffset dst ret|
-
- low := osTimeParts at:1.
- hi := osTimeParts at:2.
+ |low hi year month day hours minutes seconds millis utcOffset dst osSeconds ret|
+
+ millis := osTime \\ 1000.
+ osSeconds := osTime // 1000.
%{
struct tm *tmPtr;
struct tm *gmTmPtr;
@@ -6294,117 +6312,103 @@
# endif
#endif
- if (__bothSmallInteger(low, hi)) {
- t = (__intVal(hi) << 16) | __intVal(low);
- tmPtr = localtime(&t);
- hours = __MKSMALLINT(tmPtr->tm_hour);
- minutes = __MKSMALLINT(tmPtr->tm_min);
- seconds = __MKSMALLINT(tmPtr->tm_sec);
-
- year = __MKSMALLINT(tmPtr->tm_year + 1900);
- month = __MKSMALLINT(tmPtr->tm_mon + 1);
- day = __MKSMALLINT(tmPtr->tm_mday);
-
- if (tmPtr->tm_isdst == 0) {
- dst = false;
- utcOffset = __MKSMALLINT(TIMEZONE);
- } else {
- dst = true;
+ t = __longIntVal(osSeconds);
+
+ tmPtr = localtime(&t);
+ hours = __MKSMALLINT(tmPtr->tm_hour);
+ minutes = __MKSMALLINT(tmPtr->tm_min);
+ seconds = __MKSMALLINT(tmPtr->tm_sec);
+
+ year = __MKSMALLINT(tmPtr->tm_year + 1900);
+ month = __MKSMALLINT(tmPtr->tm_mon + 1);
+ day = __MKSMALLINT(tmPtr->tm_mday);
+
+ if (tmPtr->tm_isdst == 0) {
+ dst = false;
+ utcOffset = __MKSMALLINT(TIMEZONE);
+ } else {
+ dst = true;
#ifdef HAS_ALTZONE
- utcOffset = __MKSMALLINT(altzone);
+ utcOffset = __MKSMALLINT(altzone);
#else
- utcOffset = __MKSMALLINT(TIMEZONE) + 3600;
-#endif
- }
+ utcOffset = __MKSMALLINT(TIMEZONE) + 3600;
+#endif
}
%}.
- year notNil ifTrue:[
- "I would love to have SELF-like inline objects ..."
- ret := Array new:8.
- ret at:1 put:year.
- ret at:2 put:month.
- ret at:3 put:day.
- ret at:4 put:hours.
- ret at:5 put:minutes.
- ret at:6 put:seconds.
- ret at:7 put:utcOffset.
- ret at:8 put:dst.
- ^ ret
- ].
- ^ self primitiveFailed
-!
-
-computeTimePartsFromYear:y month:m day:d hour:h minute:min seconds:s
- "return an Array containing the OS-dependent time for the given
- time and day. The arguments are assumed to be in localtime including
- any daylight saving adjustings."
-
- |low hi|
-
-%{
- struct tm tm;
- long t;
-
- if (__bothSmallInteger(y, m)
- && __bothSmallInteger(d, h)
- && __bothSmallInteger(min, s)) {
- tm.tm_hour = __intVal(h);
- tm.tm_min = __intVal(min);
- tm.tm_sec = __intVal(s);
-
- tm.tm_year = __intVal(y) - 1900;
- tm.tm_mon = __intVal(m) - 1;
- tm.tm_mday = __intVal(d);
- tm.tm_isdst = -1;
-
- t = mktime(&tm);
- low = __MKSMALLINT(t & 0xFFFF);
- hi = __MKSMALLINT((t >> 16) & 0xFFFF);
- }
-%}.
- low notNil ifTrue:[
- ^ Array with:low with:hi
- ].
- ^ self primitiveFailed
-!
-
-computeTimePartsOf:osTimeLow and:osTimeHi for:aBlock
- "compute hours, minutes and seconds from the time-parts timeLow and
- timeHi and evaluate the argument, a 3-arg block with these.
- Conversion is to localtime including any daylight saving adjustments.
-
- This method was added to avoid LargeInteger arithmetic and to be
- independent of how the OperatingSystem represents time;
- the time-parts expected are those returned by getTimeParts."
-
- |hours minutes seconds|
-
- ((osTimeLow isMemberOf:SmallInteger)
- and:[osTimeHi isMemberOf:SmallInteger]) ifFalse:[
- ^ self primitiveFailed
- ].
+ "I would love to have SELF-like inline objects ..."
+ ret := Array new:9.
+ ret at:1 put:year.
+ ret at:2 put:month.
+ ret at:3 put:day.
+ ret at:4 put:hours.
+ ret at:5 put:minutes.
+ ret at:6 put:seconds.
+ ret at:7 put:utcOffset.
+ ret at:8 put:dst.
+ ret at:9 put:millis.
+ ^ ret
+
+ "
+ OperatingSystem n_computeTimeAndDateFrom:0
+ "
+!
+
+computeTimePartsOf:osTime for:aBlock
+ "compute hours, minutes, seconds and milliseconds from the osTime
+ and evaluate the argument, a 4-arg block with these.
+ Conversion is to localtime including any daylight saving adjustments."
+
+ |hours minutes seconds millis osSeconds|
+
+ osSeconds := osTime // 1000.
+ millis := osTime \\ 1000.
%{
struct tm *tmPtr;
long t;
- t = (__intVal(osTimeHi) << 16) | __intVal(osTimeLow);
+ t = __longIntVal(osSeconds);
+
tmPtr = localtime(&t);
hours = __MKSMALLINT(tmPtr->tm_hour);
minutes = __MKSMALLINT(tmPtr->tm_min);
seconds = __MKSMALLINT(tmPtr->tm_sec);
%}.
- aBlock value:hours value:minutes value:seconds
-!
-
-computeTimePartsOf:osTimeParts for:aBlock
- "compute hour, minute and seconds from the ostime in timeParts,
- and evaluate the argument, a 3-arg block with these.
- Conversion is to localtime including any daylight saving adjustments."
-
- ^ self
- computeTimePartsOf:(osTimeParts at:1)
- and:(osTimeParts at:2)
- for:aBlock
+ aBlock value:hours value:minutes value:seconds value:millis
+
+ "
+ OperatingSystem n_computeTimePartsOf:100 for:[:h :m :s :milli |
+ h printCR. m printCR. s printCR. millis printCR
+ ]
+ "
+!
+
+computeUTCTimePartsOf:osTime for:aBlock
+ "compute hours, minutes, seconds and milliseconds from the osTime
+ and evaluate the argument, a 4-arg block with these.
+ Conversion is to UTC."
+
+ |hours minutes seconds millis osSeconds|
+
+ osSeconds := osTime // 1000.
+ millis := osTime \\ 1000.
+%{
+ struct tm *tmPtr;
+ long t;
+
+ t = __longIntVal(osSeconds);
+
+ tmPtr = gmtime(&t);
+ hours = __MKSMALLINT(tmPtr->tm_hour);
+ minutes = __MKSMALLINT(tmPtr->tm_min);
+ seconds = __MKSMALLINT(tmPtr->tm_sec);
+%}.
+ aBlock value:hours value:minutes value:seconds value:millis
+
+ "
+ OperatingSystem n_computeUTCTimePartsOf:100 for:[:h :m :s :milli |
+ h printCR. m printCR. s printCR. milli printCR
+ ]
+ "
!
getMillisecondTime
@@ -6456,104 +6460,64 @@
%}
!
-getTime
- "return current Time in some OS dependent representation.
- (on unix, its the seconds since 1970).
-
- WARNING:
- this is OperatingSystem dependent
- - for portable code, use getTimeParts and compute*PartsOf:and:for:.
- Better yet, use Date>>today or Time>>now for fully ST-80 compatible code."
-
- ^ (OperatingSystem getTimeInto:[:low :hi | hi*16r10000 + low])
-
- "
- OperatingSystem getTime
- "
-!
-
-getTimeHi
- "return hi 16 bits of current time.
-
- OBSOLETE: Dont use this method, use getTimeParts.
- This method will NOT always return the correct time
- if used together with getTimeHi, since a wrap between
- the two getTimeXXX sends could occur.
- WARNING: this method will vanish - dont use it."
-
-%{ /* NOCONTEXT */
-
- RETURN ( __MKSMALLINT((time(0) >> 16) & 0xFFFF) );
-%}
-
- "OperatingSystem getTimeHi"
-!
-
-getTimeInto:aBlock
- "evaluate the argument aBlock, passing the time-parts of
- the current time as arguments.
- See comment in 'OperatingSystem>>getTimeParts' on what to
- do with those parts."
-
- |low hi|
-%{
+getOSTime
+ "This returns the millisecond OS time.
+
+ 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;
+#if !defined(HAS_GETTIMEOFDAY) && defined(SYSV) && defined(HZ)
+ /*
+ * sys5 time we have to fake the information
+ * the returned value inexact.
+ */
int now;
-
- now = time(0);
- hi = __MKSMALLINT((now >> 16) & 0xFFFF);
- low = __MKSMALLINT(now & 0xFFFF);
+ 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);
+
+#else
+# ifdef MSDOS_LIKE
+ struct _timeb timebuffer;
+
+ _ftime(&timebuffer);
+ seconds = __MKUINT(timebuffer.time);
+ millis = __MKSMALLINT(timebuffer.millitm);
+
+# else /* assume HAS_GETTIMEOFDAY */
+ /*
+ * bsd time
+ */
+ struct timeval tb;
+ struct timezone tzb;
+
+ gettimeofday(&tb, &tzb);
+ seconds = __MKUINT(tb.tv_sec);
+ millis = __MKSMALLINT(tb.tv_usec / 1000);
+
+# endif
+#endif
%}.
- ^ aBlock value:low value:hi
-
- "
- OperatingSystem getTimeInto:[:low :hi | low printNewline. hi printNewline]
- "
-!
-
-getTimeLow
- "return low 16 bits of current time.
-
- OBSOLETE: Dont use this method, use getTimeParts.
- This method will not always return the correct time
- if used together with getTimeHi, since a wrap between
- the two getTimeXXX sends could occur.
- WARNING: this method will vanish - dont use it."
-
-%{ /* NOCONTEXT */
-
- RETURN ( __MKSMALLINT(time(0) & 0xFFFF) );
-%}
-
- "
- OperatingSystem getTimeLow
- "
-!
-
-getTimeParts
- "return the current time as an array of 2 integers representing
- the current time (usually low 16bits / hi 16 bits) in some OS
- dependent way.
-
- On unix, the values represent the seconds since 1970, on other
- systems this may be different.
- WARNING:
- for portability, never use these values directly, but pass them
- to #computeTimeParts and/or #computeDatePartsOf:, which know how to
- interpret them.
- Better yet, use Date>>today and Time>>now for ST-80 compatibility."
-
- |low hi|
-%{
- int now;
-
- now = time(0);
- hi = __MKSMALLINT((now >> 16) & 0xFFFF);
- low = __MKSMALLINT(now & 0xFFFF);
-%}.
- ^ Array with:low with:hi
-
- "
- OperatingSystem getTimeParts
+ ^ (seconds * 1000) + millis
+
+ "
+ OperatingSystem n_getOSTime printCR.
+ Delay waitForSeconds:0.2.
+ OperatingSystem n_getOSTime printCR.
"
!
@@ -7403,6 +7367,6 @@
!OperatingSystem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.146 1996-06-29 12:14:27 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.147 1996-07-01 13:26:33 cg Exp $'
! !
OperatingSystem initialize!