home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / unixlib36d / UnixLib36d / src / unix / c / time < prev    next >
Encoding:
Text File  |  1994-03-08  |  1.0 KB  |  68 lines

  1. static char sccs_id[] = "@(#) time.c 1.0 " __DATE__ " HJR";
  2.  
  3. /* time.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <time.h>
  6. #include <errno.h>
  7.  
  8. #include "sys/os.h"
  9. #include "sys/syslib.h"
  10.  
  11. clock_t
  12. clock (void)
  13. {
  14.   unsigned int b[2];
  15.   unsigned int t1, t2;
  16.   os_error *e;
  17.  
  18.   *((char *) b) = 3;
  19.   if (e = os_word (0x0e, b))
  20.     {
  21.       __seterr (e);
  22.       return (-1);
  23.     }
  24.  
  25.   t1 = (b[0]);
  26.   t2 = (b[1] & 0xff);
  27.  
  28.   if (t2 - __time[1])
  29.     {
  30.       errno = ERANGE;
  31.       return ((clock_t) - 1);
  32.     }
  33.  
  34.   return (t1 - __time[0]);
  35. }
  36.  
  37. time_t
  38. time (time_t * t)
  39. {
  40.   unsigned int b[2];
  41.   unsigned int t1, t2, tc;
  42.   os_error *e;
  43.  
  44.   *((char *) b) = 3;
  45.   if (e = os_word (0x0e, b))
  46.     {
  47.       __seterr (e);
  48.       return (-1);
  49.     }
  50.  
  51.   t1 = (b[0]);
  52.   t2 = (b[1] & 0xff);
  53.  
  54.   tc = 0x6e996a00U;
  55.   if (t1 < tc)
  56.     t2--;
  57.   t1 -= tc;
  58.   t2 -= 0x33;            /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */
  59.  
  60.   t1 = (t1 / 100) + (t2 * 42949673U);    /* 0x100000000 / 100 = 42949672.96 */
  61.   t1 -= (t2 / 25);        /* compensate for .04 error */
  62.  
  63.   if (t)
  64.     *t = t1;
  65.  
  66.   return (t1);
  67. }
  68.