home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3998 / time.c < prev   
C/C++ Source or Header  |  1991-09-08  |  3KB  |  140 lines

  1. /*
  2.  * @(#)time.c    1.5 91/09/05
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/ptrace.h>
  8. #include <sys/time.h>
  9.  
  10. #include "defs.h"
  11.  
  12. void
  13. printtv(pid, addr)
  14. {
  15.     struct timeval tv;
  16.  
  17.     if (addr == 0 || umove(pid, addr, sizeof tv, (char *)&tv) < 0) {
  18.         fprintf(outf, "(struct timeval *)0");
  19.     } else {
  20.         fprintf(outf, "{%u,%u}", tv.tv_sec, tv.tv_usec);
  21.     }
  22. }
  23.  
  24. int
  25. sys_gettimeofday(tcp)
  26. struct tcb *tcp;
  27. {
  28.     struct timeval tv;
  29.     struct timezone tz;
  30.  
  31.     if (exiting(tcp)) {
  32.         if (syserror(tcp)) {
  33.             fprintf(outf, "%#x, %#x",
  34.                     tcp->u_args[0], tcp->u_args[1]);
  35.             return 0;
  36.         }
  37.         printtv(tcp->pid, tcp->u_args[0]);
  38.         if (tcp->u_args[1] == 0 || umove(tcp->pid, tcp->u_args[1],
  39.                         sizeof tz, (char *)&tz) < 0) {
  40.             fprintf(outf, ", (struct timezone *)0");
  41.         } else {
  42.             fprintf(outf, ", {%d west,%d dst}",
  43.                 tz.tz_minuteswest, tz.tz_dsttime);
  44.         }
  45.     }
  46.     return 0;
  47. }
  48.  
  49. int
  50. sys_settimeofday(tcp)
  51. struct tcb *tcp;
  52. {
  53.     struct timeval tv;
  54.     struct timezone tz;
  55.  
  56.     if (entering(tcp)) {
  57.         printtv(tcp->pid, tcp->u_args[0]);
  58.         if (tcp->u_args[1] == 0 || umove(tcp->pid, tcp->u_args[1],
  59.                         sizeof tz, (char *)&tz) < 0) {
  60.             fprintf(outf, ", (struct timezone *)0");
  61.         } else {
  62.             fprintf(outf, ", {%d west,%d dst}",
  63.                 tz.tz_minuteswest, tz.tz_dsttime);
  64.         }
  65.     }
  66.     return 0;
  67. }
  68.  
  69. int
  70. sys_adjtime(tcp)
  71. struct tcb *tcp;
  72. {
  73.     struct timeval tv;
  74.  
  75.     if (entering(tcp)) {
  76.         printtv(tcp->pid, tcp->u_args[0]);
  77.         fprintf(outf, ", ");
  78.     } else {
  79.         if (syserror(tcp))
  80.             fprintf(outf, "%#x", tcp->u_args[1]);
  81.         else
  82.             printtv(tcp->pid, tcp->u_args[1]);
  83.     }
  84. }
  85.  
  86. static Xlat which[] = {
  87.     ITIMER_REAL,    "ITIMER_REAL",
  88.     ITIMER_VIRTUAL,    "ITIMER_VIRTUAL",
  89.     ITIMER_PROF,    "ITIMER_PROF",
  90.     0,        NULL,
  91. };
  92.  
  93. static void
  94. printitv(pid, addr)
  95. {
  96.     struct itimerval itv;
  97.  
  98.     if (addr == 0 || umove(pid, addr, sizeof itv, (char *)&itv) < 0) {
  99.         fprintf(outf, "(struct itimerval *)0");
  100.     } else {
  101.         fprintf(outf, "{{%u,%u},{%u,%u}}",
  102.         itv.it_interval.tv_sec, itv.it_interval.tv_usec,
  103.         itv.it_value.tv_sec, itv.it_value.tv_usec);
  104.     }
  105. }
  106.  
  107. int
  108. sys_getitimer(tcp)
  109. struct tcb *tcp;
  110. {
  111.     if (entering(tcp)) {
  112.         printxval(which, tcp->u_args[0], "ITMER_???");
  113.         fprintf(outf, ", ");
  114.     } else {
  115.         if (syserror(tcp))
  116.             fprintf(outf, "%#x", tcp->u_args[1]);
  117.         else
  118.             printitv(tcp->pid, tcp->u_args[1]);
  119.     }
  120.     return 0;
  121. }
  122.  
  123. int
  124. sys_setitimer(tcp)
  125. struct tcb *tcp;
  126. {
  127.     if (entering(tcp)) {
  128.         printxval(which, tcp->u_args[0], "ITMER_???");
  129.         fprintf(outf, ", ");
  130.         printitv(tcp->pid, tcp->u_args[1]);
  131.         fprintf(outf, ", ");
  132.     } else {
  133.         if (syserror(tcp))
  134.             fprintf(outf, "%#x", tcp->u_args[2]);
  135.         else
  136.             printitv(tcp->pid, tcp->u_args[2]);
  137.     }
  138.     return 0;
  139. }
  140.