home *** CD-ROM | disk | FTP | other *** search
- /* e_gettimeofday.c */
- /* 18Oct95 e -- from runtime.c */
-
- #include <utime.h>
-
- #define TICKS_PER_SEC 60
-
- #if 0
-
- // this still gives "backward running" time sometimes...
-
- void gettimeofday ( struct timeval *t, int huh )
- {
- unsigned long now1, now2, ticks;
- int be_safe = 1000;
-
- now2 = LMGetTime();
- do
- { now1 = now2;
- ticks = LMGetTicks();
- now2 = LMGetTime();
- } while( now1 != now2 && --be_safe > 0 );
- ticks = ((ticks % TICKS_PER_SEC) * 1000000) / TICKS_PER_SEC;
- t->tv_sec = now1;
- t->tv_usec = ticks;
- }
-
- #else
-
- static long tod_offset;
-
- void gettimeofday ( struct timeval *t, int huh )
- {
- #pragma unused ( huh )
- unsigned long now, ticks, secs;
- long offs;
- now = LMGetTime(); // get Mac Time
- ticks = LMGetTicks(); // get Mac Ticks
- // convert ticks to timeofday
- secs = ticks / TICKS_PER_SEC; // floor
- ticks -= secs * TICKS_PER_SEC; // mod
- secs += tod_offset; // offset
- ticks = (ticks * 1000000) / TICKS_PER_SEC; // ticks -> usecs
- // see if the Mac clock was changed
- offs = secs - now;
- if( offs != 0 && offs != 1 && offs != -1)
- { // off by one second is OK
- tod_offset -= offs;
- secs -= offs; // rts - (rts - now) => now
- }
- #if ( __MWERKS__ >= 0x1100 )
- /* seconds between 1/1/1900 and 1/1/1904 */
- t->tv_sec = secs + (365L * 4L) * 24L * 60L * 60L;
- #else
- t->tv_sec = secs;
- #endif
- t->tv_usec = ticks;
- }
-
- #endif
-
- // end
-