home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / tcl / os2 / tclOS2Time.c < prev    next >
C/C++ Source or Header  |  1998-08-07  |  3KB  |  137 lines

  1. /* 
  2.  * tclOS2Time.c --
  3.  *
  4.  *    Contains OS/2 specific versions of Tcl functions that
  5.  *    obtain time values from the operating system.
  6.  *
  7.  * Copyright 1995 by Sun Microsystems, Inc.
  8.  * Copyright 1996-1997 Illya Vaes
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  *
  13.  */
  14.  
  15. #include "tclInt.h"
  16. #include "tclPort.h"
  17.  
  18. /*
  19.  *----------------------------------------------------------------------
  20.  *
  21.  * TclGetSeconds --
  22.  *
  23.  *    This procedure returns the number of seconds from the epoch.
  24.  *    On most Unix systems the epoch is Midnight Jan 1, 1970 GMT.
  25.  *      This goes for OS/2 with EMX too.
  26.  *
  27.  * Results:
  28.  *    Number of seconds from the epoch.
  29.  *
  30.  * Side effects:
  31.  *    None.
  32.  *
  33.  *----------------------------------------------------------------------
  34.  */
  35.  
  36. unsigned long
  37. TclGetSeconds()
  38. {
  39.     return (unsigned long) time((time_t *) NULL);
  40. }
  41.  
  42. /*
  43.  *----------------------------------------------------------------------
  44.  *
  45.  * TclGetClicks --
  46.  *
  47.  *    This procedure returns a value that represents the highest
  48.  *    resolution clock available on the system.  There are no
  49.  *    guarantees on what the resolution will be.  In Tcl we will
  50.  *    call this value a "click".  The start time is also system
  51.  *    dependant.
  52.  *
  53.  * Results:
  54.  *    Number of clicks from some start time.
  55.  *
  56.  * Side effects:
  57.  *    None.
  58.  *
  59.  *----------------------------------------------------------------------
  60.  */
  61.  
  62. unsigned long
  63. TclGetClicks()
  64. {
  65. #ifndef CLI_VERSION
  66.     return WinGetCurrentTime(hab);
  67. #else
  68.     QWORD timer;
  69.     DosTmrQueryTime(&timer);
  70.     return timer.ulLo;
  71. #endif
  72. }
  73.  
  74. /*
  75.  *----------------------------------------------------------------------
  76.  *
  77.  * TclGetTimeZone --
  78.  *
  79.  *    Determines the current timezone.  The method varies wildly
  80.  *    between different Platform implementations, so its hidden in
  81.  *    this function.
  82.  *
  83.  * Results:
  84.  *    Hours east of GMT.
  85.  *
  86.  * Side effects:
  87.  *    None.
  88.  *
  89.  *----------------------------------------------------------------------
  90.  */
  91.  
  92. int
  93. TclGetTimeZone (currentTime)
  94.     unsigned long  currentTime;
  95. {
  96.     static int setTZ = 0;
  97.     int timeZone;
  98.  
  99.     if (!setTZ) {
  100.         tzset();
  101.         setTZ = 1;
  102.     }
  103.     /* EMX has "timezone" variable with seconds *west* of Greenwich */
  104.     /* include <time.h> */
  105.     timeZone = - (timezone / 3600);
  106.  
  107.     return timeZone;
  108. }
  109.  
  110. /*
  111.  *----------------------------------------------------------------------
  112.  *
  113.  * TclGetTime --
  114.  *
  115.  *    Gets the current system time in seconds and microseconds
  116.  *    since the beginning of the epoch: 00:00 UCT, January 1, 1970.
  117.  *
  118.  * Results:
  119.  *    Returns the current time in timePtr.
  120.  *
  121.  * Side effects:
  122.  *    None.
  123.  *
  124.  *----------------------------------------------------------------------
  125.  */
  126.  
  127. void
  128. TclGetTime(timePtr)
  129.     Tcl_Time *timePtr;        /* Location to store time information. */
  130. {
  131.     struct timeb t;
  132.  
  133.     ftime(&t);
  134.     timePtr->sec = t.time;
  135.     timePtr->usec = t.millitm * 1000;
  136. }
  137.