home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / src / unix / c / time < prev    next >
Encoding:
Text File  |  1994-09-30  |  1.3 KB  |  81 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/times.h>
  9.  
  10. #include "sys/os.h"
  11. #include "sys/syslib.h"
  12.  
  13. clock_t
  14. clock (void)
  15. {
  16.   unsigned int b[2];
  17.   unsigned int t1, t2;
  18.   os_error *e;
  19.  
  20.   *((char *) b) = 3;
  21.   if (e = os_word (0x0e, b))
  22.     {
  23.       __seterr (e);
  24.       return (-1);
  25.     }
  26.  
  27.   t1 = (b[0]);
  28.   t2 = (b[1] & 0xff);
  29.  
  30.   if (t2 - __time[1])
  31.     {
  32.       errno = ERANGE;
  33.       return ((clock_t) - 1);
  34.     }
  35.  
  36.   return (t1 - __time[0]);
  37. }
  38.  
  39. time_t
  40. time (time_t * t)
  41. {
  42.   unsigned int b[2];
  43.   unsigned int t1, t2, tc;
  44.   os_error *e;
  45.  
  46.   *((char *) b) = 3;
  47.   if (e = os_word (0x0e, b))
  48.     {
  49.       __seterr (e);
  50.       return (-1);
  51.     }
  52.  
  53.   t1 = (b[0]);
  54.   t2 = (b[1] & 0xff);
  55.  
  56.   tc = 0x6e996a00U;
  57.   if (t1 < tc)
  58.     t2--;
  59.   t1 -= tc;
  60.   t2 -= 0x33;            /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */
  61.  
  62.   t1 = (t1 / 100) + (t2 * 42949673U);    /* 0x100000000 / 100 = 42949672.96 */
  63.   t1 -= (t2 / 25);        /* compensate for .04 error */
  64.  
  65.   if (t)
  66.     *t = t1;
  67.  
  68.   return (t1);
  69. }
  70.  
  71. clock_t
  72. times (struct tms * tmsp)
  73.  
  74. {
  75.   tmsp->tms_utime = clock ();    /* user time */
  76.   tmsp->tms_stime = 0;        /* system time */
  77.   tmsp->tms_cutime = 0;        /* user time, children */
  78.   tmsp->tms_cstime = 0;        /* system time, children */
  79.   return tmsp->tms_utime;
  80. }
  81.