home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3998 / io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-09  |  2.3 KB  |  125 lines

  1. /*
  2.  * @(#)io.c    1.5 91/09/05
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <fcntl.h>
  8. #include <sys/ptrace.h>
  9. #include <sys/uio.h>
  10.  
  11. #include "defs.h"
  12.  
  13. int
  14. sys_read(tcp)
  15. struct tcb *tcp;
  16. {
  17.     if (entering(tcp)) {
  18.         fprintf(outf, "%u, ", tcp->u_args[0]);
  19.     } else {
  20.         if (syserror(tcp))
  21.             fprintf(outf, "%#x", tcp->u_args[1]);
  22.         else
  23.             printstr(tcp->pid, tcp->u_args[1], tcp->u_rval);
  24.         fprintf(outf, ", %u", tcp->u_args[2]);
  25.     }
  26.     return 0;
  27. }
  28.  
  29. int
  30. sys_write(tcp)
  31. struct tcb *tcp;
  32. {
  33.     if (entering(tcp)) {
  34.         fprintf(outf, "%u, ", tcp->u_args[0]);
  35.         printstr(tcp->pid, tcp->u_args[1], tcp->u_args[2]);
  36.         fprintf(outf, ", %u", tcp->u_args[2]);
  37.     }
  38.     return 0;
  39. }
  40.  
  41. int
  42. sys_readv(tcp)
  43. struct tcb *tcp;
  44. {
  45.     struct iovec *iov;
  46.     int i, len;
  47.  
  48.     if (entering(tcp)) {
  49.         fprintf(outf, "%u, ", tcp->u_args[0]);
  50.     } else {
  51.         if (syserror(tcp)) {
  52.             fprintf(outf, "%#x, %u",
  53.                     tcp->u_args[1], tcp->u_args[2]);
  54.             return 0;
  55.         }
  56.         len = tcp->u_args[2];
  57.         if ((iov = (struct iovec *)malloc(len * sizeof *iov)) == NULL) {
  58.             fprintf(stderr, "No memory");
  59.             return 0;
  60.         }
  61.         if (umove(tcp->pid, tcp->u_args[1],
  62.                 len * sizeof *iov, (char *)iov) < 0) {
  63.             fprintf(outf, "%#x", tcp->u_args[1]);
  64.         } else {
  65.             for (i = 0; i < len; i++) {
  66.                 printstr(tcp->pid, iov[i].iov_base,
  67.                             iov[i].iov_len);
  68.             }
  69.         }
  70.         free((char *)iov);
  71.         fprintf(outf, ", %u", tcp->u_args[2]);
  72.     }
  73.     return 0;
  74. }
  75.  
  76. int
  77. sys_writev(tcp)
  78. struct tcb *tcp;
  79. {
  80.     struct iovec *iov;
  81.     int i, len;
  82.  
  83.     if (entering(tcp)) {
  84.         fprintf(outf, "%u, ", tcp->u_args[0]);
  85.         len = tcp->u_args[2];
  86.         if ((iov = (struct iovec *)malloc(len * sizeof *iov)) == NULL) {
  87.             fprintf(stderr, "No memory");
  88.             return 0;
  89.         }
  90.         if (umove(tcp->pid, tcp->u_args[1],
  91.                 len * sizeof *iov, (char *)iov) < 0) {
  92.             fprintf(outf, "%#x", tcp->u_args[1]);
  93.         } else {
  94.             for (i = 0; i < len; i++) {
  95.                 printstr(tcp->pid, iov[i].iov_base,
  96.                             iov[i].iov_len);
  97.             }
  98.         }
  99.         free((char *)iov);
  100.         fprintf(outf, ", %u", tcp->u_args[2]);
  101.     }
  102.     return 0;
  103. }
  104.  
  105. int
  106. sys_ioctl(tcp)
  107. struct tcb *tcp;
  108. {
  109.     char *symbol, *ioctl_lookup();
  110.     int ioctl_decode();
  111.  
  112.     if (entering(tcp)) {
  113.         fprintf(outf, "%u, ", tcp->u_args[0]);
  114.         symbol = ioctl_lookup(tcp->u_args[1]);
  115.         if (symbol)
  116.             fprintf(outf, "%s, ", symbol);
  117.         else
  118.             fprintf(outf, "%#x, ", tcp->u_args[1]);
  119.  
  120.         if (ioctl_decode(tcp->pid, tcp->u_args[1], tcp->u_args[2]) == 0)
  121.             fprintf(outf, "%#x", tcp->u_args[2]);
  122.     }
  123.     return 0;
  124. }
  125.