finally works (updated for 4.1c and merged with sun)
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Fri, 31 Dec 1982 09:35:50 +0000 (01:35 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Fri, 31 Dec 1982 09:35:50 +0000 (01:35 -0800)
SCCS-vsn: bin/csh/exec.c 4.5
SCCS-vsn: bin/csh/func.c 4.7
SCCS-vsn: bin/csh/csh.h 4.5
SCCS-vsn: bin/csh/hist.c 4.4
SCCS-vsn: bin/csh/proc.c 4.7
SCCS-vsn: bin/csh/proc.h 4.2
SCCS-vsn: bin/csh/time.c 4.2

usr/src/bin/csh/csh.h
usr/src/bin/csh/exec.c
usr/src/bin/csh/func.c
usr/src/bin/csh/hist.c
usr/src/bin/csh/proc.c
usr/src/bin/csh/proc.h
usr/src/bin/csh/time.c

index 5bd3859..3f40060 100644 (file)
@@ -1,9 +1,8 @@
-/* csh.h 4.4 %G% */
+/* csh.h 4.5 82/12/30 */
 
 #include "sh.local.h"
 
 #include "sh.local.h"
-#ifdef VMUNIX
-#include <sys/vtimes.h>
-#endif
+#include <time.h>
+#include <resource.h>
 
 /*
  * C shell
 
 /*
  * C shell
@@ -59,6 +58,7 @@ char  *err;                   /* Error message from scanner/parser */
 int    errno;                  /* Error from C library routines */
 char   *shtemp;                /* Temp name for << shell files in /tmp */
 time_t time0;                  /* Time at which the shell started */
 int    errno;                  /* Error from C library routines */
 char   *shtemp;                /* Temp name for << shell files in /tmp */
 time_t time0;                  /* Time at which the shell started */
+struct rusage ru0;
 
 /*
  * Miscellany
 
 /*
  * Miscellany
@@ -199,11 +199,7 @@ struct     wordent {
  * process id's from `$$', and modified variable values (from qualifiers
  * during expansion in sh.dol.c) here.
  */
  * process id's from `$$', and modified variable values (from qualifiers
  * during expansion in sh.dol.c) here.
  */
-#ifdef VMUNIX
 char   labuf[BUFSIZ];
 char   labuf[BUFSIZ];
-#else
-char   labuf[256];
-#endif
 
 char   *lap;
 
 
 char   *lap;
 
@@ -437,10 +433,6 @@ char       **Vav;
 char   *Vdp;
 #endif
 
 char   *Vdp;
 #endif
 
-#ifdef VMUNIX
-struct vtimes zvms;
-#endif
-
 char   **evalvec;
 char   *evalp;
 
 char   **evalvec;
 char   *evalp;
 
index 488dbc3..1040e3e 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)exec.c 4.4 %G%";
+static char *sccsid = "@(#)exec.c 4.5 %G%";
 
 #include "sh.h"
 #include <dir.h>
 
 #include "sh.h"
 #include <dir.h>
index 87f35cd..0646e09 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)func.c 4.6 81/08/20";
+static char *sccsid = "@(#)func.c 4.7 82/12/30";
 
 #include "sh.h"
 #include <sys/ioctl.h>
 
 #include "sh.h"
 #include <sys/ioctl.h>
@@ -820,7 +820,6 @@ doumask(v)
        umask(i);
 }
 
        umask(i);
 }
 
-#include <sys/vlimit.h>
 
 struct limits {
        int     limconst;
 
 struct limits {
        int     limconst;
@@ -828,13 +827,12 @@ struct limits {
        int     limdiv;
        char    *limscale;
 } limits[] = {
        int     limdiv;
        char    *limscale;
 } limits[] = {
-       LIM_NORAISE,    "noraise",      1,      "",
-       LIM_CPU,        "cputime",      1,      "seconds",
-       LIM_FSIZE,      "filesize",     1024,   "kbytes",
-       LIM_DATA,       "datasize",     1024,   "kbytes",
-       LIM_STACK,      "stacksize",    1024,   "kbytes",
-       LIM_CORE,       "coredumpsize", 1024,   "kbytes",
-       LIM_MAXRSS,     "memoryuse",    1024,   "kbytes",
+       RLIMIT_CPU,     "cputime",      1,      "seconds",
+       RLIMIT_FSIZE,   "filesize",     1024,   "kbytes",
+       RLIMIT_DATA,    "datasize",     1024,   "kbytes",
+       RLIMIT_STACK,   "stacksize",    1024,   "kbytes",
+       RLIMIT_CORE,    "coredumpsize", 1024,   "kbytes",
+       RLIMIT_RSS,     "memoryuse",    1024,   "kbytes",
        -1,             0,
 };
 
        -1,             0,
 };
 
@@ -866,8 +864,6 @@ dolimit(v)
        if (*v == 0) {
                for (lp = limits+1; lp->limconst >= 0; lp++)
                        plim(lp);
        if (*v == 0) {
                for (lp = limits+1; lp->limconst >= 0; lp++)
                        plim(lp);
-               if (vlimit(LIM_NORAISE, -1) && getuid())
-                       printf("Limits cannot be raised\n");
                return;
        }
        lp = findlim(v[0]);
                return;
        }
        lp = findlim(v[0]);
@@ -895,30 +891,28 @@ getval(lp, v)
                        return ((int)(f+0.5) * lp->limdiv);
                cp = *v;
        }
                        return ((int)(f+0.5) * lp->limdiv);
                cp = *v;
        }
-       if (lp->limconst == LIM_NORAISE)
-               goto badscal;
        switch (*cp) {
 
        case ':':
        switch (*cp) {
 
        case ':':
-               if (lp->limconst != LIM_CPU)
+               if (lp->limconst != RLIMIT_CPU)
                        goto badscal;
                return ((int)(f * 60.0 + atof(cp+1)));
 
        case 'h':
                        goto badscal;
                return ((int)(f * 60.0 + atof(cp+1)));
 
        case 'h':
-               if (lp->limconst != LIM_CPU)
+               if (lp->limconst != RLIMIT_CPU)
                        goto badscal;
                limtail(cp, "hours");
                f *= 3600.;
                break;
 
        case 'm':
                        goto badscal;
                limtail(cp, "hours");
                f *= 3600.;
                break;
 
        case 'm':
-               if (lp->limconst == LIM_CPU) {
+               if (lp->limconst == RLIMIT_CPU) {
                        limtail(cp, "minutes");
                        f *= 60.;
                        break;
                }
        case 'M':
                        limtail(cp, "minutes");
                        f *= 60.;
                        break;
                }
        case 'M':
-               if (lp->limconst == LIM_CPU)
+               if (lp->limconst == RLIMIT_CPU)
                        goto badscal;
                *cp = 'm';
                limtail(cp, "megabytes");
                        goto badscal;
                *cp = 'm';
                limtail(cp, "megabytes");
@@ -926,13 +920,13 @@ getval(lp, v)
                break;
 
        case 's':
                break;
 
        case 's':
-               if (lp->limconst != LIM_CPU)
+               if (lp->limconst != RLIMIT_CPU)
                        goto badscal;
                limtail(cp, "seconds");
                break;
 
        case 'k':
                        goto badscal;
                limtail(cp, "seconds");
                break;
 
        case 'k':
-               if (lp->limconst == LIM_CPU)
+               if (lp->limconst == RLIMIT_CPU)
                        goto badscal;
                limtail(cp, "kbytes");
                f *= 1024;
                        goto badscal;
                limtail(cp, "kbytes");
                f *= 1024;
@@ -940,7 +934,7 @@ getval(lp, v)
 
        case 'u':
                limtail(cp, "unlimited");
 
        case 'u':
                limtail(cp, "unlimited");
-               return (INFINITY);
+               return (RLIM_INFINITY);
 
        default:
 badscal:
 
        default:
 badscal:
@@ -963,16 +957,16 @@ limtail(cp, str0)
 plim(lp)
        register struct limits *lp;
 {
 plim(lp)
        register struct limits *lp;
 {
-       register int lim;
+       struct rlimit rlim;
 
        printf("%s \t", lp->limname);
 
        printf("%s \t", lp->limname);
-       lim = vlimit(lp->limconst, -1);
-       if (lim == INFINITY)
+       getrlimit(lp->limconst, &rlim);
+       if (rlim.rlim_cur == RLIM_INFINITY)
                printf("unlimited");
                printf("unlimited");
-       else if (lp->limconst == LIM_CPU)
-               psecs((long)lim);
+       else if (lp->limconst == RLIMIT_CPU)
+               psecs((long)rlim.rlim_cur);
        else
        else
-               printf("%d %s", lim / lp->limdiv, lp->limscale);
+               printf("%d %s", rlim.rlim_cur / lp->limdiv, lp->limscale);
        printf("\n");
 }
 
        printf("\n");
 }
 
@@ -984,20 +978,23 @@ dounlimit(v)
        v++;
        if (*v == 0) {
                for (lp = limits+1; lp->limconst >= 0; lp++)
        v++;
        if (*v == 0) {
                for (lp = limits+1; lp->limconst >= 0; lp++)
-                       setlim(lp, INFINITY);
+                       setlim(lp, RLIM_INFINITY);
                return;
        }
        while (*v) {
                lp = findlim(*v++);
                return;
        }
        while (*v) {
                lp = findlim(*v++);
-               setlim(lp, INFINITY);
+               setlim(lp, RLIM_INFINITY);
        }
 }
 
 setlim(lp, limit)
        register struct limits *lp;
 {
        }
 }
 
 setlim(lp, limit)
        register struct limits *lp;
 {
+       struct rlimit rlim;
 
 
-       if (vlimit(lp->limconst, limit) < 0)
+       getrlimit(lp->limconst, &rlim);
+       rlim.rlim_cur = limit;
+       if (setrlimit(lp->limconst, &rlim) < 0)
                Perror(bname);
 }
 
                Perror(bname);
 }
 
index 5d8a379..8a68351 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)hist.c 4.3 %G%";
+static char *sccsid = "@(#)hist.c 4.4 %G%";
 
 #include "sh.h"
 
 
 #include "sh.h"
 
@@ -75,7 +75,7 @@ dohist(vp)
        if (setintr)
                sigrelse(SIGINT);
        vp++;
        if (setintr)
                sigrelse(SIGINT);
        vp++;
-       while (*vp[0] == '-') {
+       while (*vp && *vp[0] == '-') {
                if (*vp && eq(*vp, "-h")) {
                        hflg++;
                        vp++;
                if (*vp && eq(*vp, "-h")) {
                        hflg++;
                        vp++;
index fdf3b69..b92a066 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)proc.c      4.6 (Berkeley) 81/05/03";
+static char *sccsid = "@(#)proc.c      4.7 (Berkeley) 82/12/30";
 
 #include "sh.h"
 #include "sh.dir.h"
 
 #include "sh.h"
 #include "sh.dir.h"
@@ -26,19 +26,13 @@ pchild()
        register int pid;
        union wait w;
        int jobflags;
        register int pid;
        union wait w;
        int jobflags;
-#ifdef VMUNIX
-       struct vtimes vt;
-#endif
+       struct rusage ru;
 
        if (!timesdone)
                timesdone++, times(&shtimes);
 loop:
        pid = wait3(&w.w_status, (setintr ? WNOHANG|WUNTRACED:WNOHANG),
 
        if (!timesdone)
                timesdone++, times(&shtimes);
 loop:
        pid = wait3(&w.w_status, (setintr ? WNOHANG|WUNTRACED:WNOHANG),
-#ifndef VMUNIX
-           0);
-#else
-           &vt);
-#endif
+           &ru);
        if (pid <= 0) {
                if (errno == EINTR) {
                        errno = 0;
        if (pid <= 0) {
                if (errno == EINTR) {
                        errno = 0;
@@ -69,9 +63,7 @@ found:
                        pp->p_stime = shtimes.tms_cstime - oldcstimes;
                } else
                        times(&shtimes);
                        pp->p_stime = shtimes.tms_cstime - oldcstimes;
                } else
                        times(&shtimes);
-#ifdef VMUNIX
-               pp->p_vtimes = vt;
-#endif
+               pp->p_rusage = ru;
                if (WIFSIGNALED(w)) {
                        if (w.w_termsig == SIGINT)
                                pp->p_flags |= PINTERRUPTED;
                if (WIFSIGNALED(w)) {
                        if (w.w_termsig == SIGINT)
                                pp->p_flags |= PINTERRUPTED;
@@ -82,11 +74,7 @@ found:
                        pp->p_reason = w.w_termsig;
                } else {
                        pp->p_reason = w.w_retcode;
                        pp->p_reason = w.w_termsig;
                } else {
                        pp->p_reason = w.w_retcode;
-#ifdef IIASA
-                       if (pp->p_reason >= 3)
-#else
                        if (pp->p_reason != 0)
                        if (pp->p_reason != 0)
-#endif
                                pp->p_flags |= PAEXITED;
                        else
                                pp->p_flags |= PNEXITED;
                                pp->p_flags |= PAEXITED;
                        else
                                pp->p_flags |= PNEXITED;
@@ -632,11 +620,10 @@ prcomd:
                if (pp->p_flags&PPTIME && !(status&(PSTOPPED|PRUNNING))) {
                        if (linp != linbuf)
                                printf("\n\t");
                if (pp->p_flags&PPTIME && !(status&(PSTOPPED|PRUNNING))) {
                        if (linp != linbuf)
                                printf("\n\t");
-#ifndef VMUNIX
-                       ptimes(pp->p_utime, pp->p_stime, pp->p_etime-pp->p_btime);
-#else
-                       pvtimes(&zvms, &pp->p_vtimes, pp->p_etime - pp->p_btime);
-#endif
+                       { static struct rusage zru;
+                         prusage(&zru, &pp->p_rusage,
+                             pp->p_etime - pp->p_btime);
+                       }
                }
                if (tp == pp->p_friends) {
                        if (linp != linbuf)
                }
                if (tp == pp->p_friends) {
                        if (linp != linbuf)
@@ -660,29 +647,17 @@ ptprint(tp)
        register struct process *tp;
 {
        time_t tetime = 0;
        register struct process *tp;
 {
        time_t tetime = 0;
-#ifdef VMUNIX
-       struct vtimes vmt;
-#else
-       time_t tutime = 0, tstime = 0;
-#endif
+       struct rusage ru;
+       static struct rusage zru;
        register struct process *pp = tp;
 
        register struct process *pp = tp;
 
-       vmt = zvms;
+       ru = zru;
        do {
        do {
-#ifdef VMUNIX
-               vmsadd(&vmt, &pp->p_vtimes);
-#else
-               tutime += pp->p_utime;
-               tstime += pp->p_stime;
-#endif
+               ruadd(&ru, &pp->p_rusage);
                if (pp->p_etime - pp->p_btime > tetime)
                        tetime = pp->p_etime - pp->p_btime;
        } while ((pp = pp->p_friends) != tp);
                if (pp->p_etime - pp->p_btime > tetime)
                        tetime = pp->p_etime - pp->p_btime;
        } while ((pp = pp->p_friends) != tp);
-#ifdef VMUNIX
-       pvtimes(&zvms, &vmt, tetime);
-#else
-       ptimes(tutime, tstime, tetime);
-#endif
+       prusage(&zru, &ru, tetime);
 }
 
 /*
 }
 
 /*
index 8522eaa..0cb12a4 100644 (file)
@@ -1,4 +1,4 @@
-/* proc.h 4.1 %G% */
+/* proc.h 4.2 %G% */
 
 /*
  * C shell - process structure declarations
 
 /*
  * C shell - process structure declarations
@@ -26,9 +26,7 @@ struct process        {
        time_t  p_etime;                /* end time */
        long    p_stime;                /* system cpu time */
        long    p_utime;                /* user cpu time */
        time_t  p_etime;                /* end time */
        long    p_stime;                /* system cpu time */
        long    p_utime;                /* user cpu time */
-#ifdef VMUNIX
-       struct  vtimes p_vtimes;
-#endif
+       struct  rusage p_rusage;
        char    *p_command;             /* first PMAXLEN chars of command */
 };
 
        char    *p_command;             /* first PMAXLEN chars of command */
 };
 
index f53da34..e9ed8b1 100644 (file)
@@ -1,26 +1,21 @@
-static char *sccsid = "@(#)time.c 4.1 %G%";
+/*     time.c  4.2     82/12/30        */
 
 #include "sh.h"
 
 /*
  * C Shell - routines handling process timing and niceing
  */
 
 #include "sh.h"
 
 /*
  * C Shell - routines handling process timing and niceing
  */
-#ifdef VMUNIX
-struct vtimes vm0;
-#else
 struct tms times0;
 struct tms timesdol;
 struct tms times0;
 struct tms timesdol;
-#endif
 
 settimes()
 {
 
 settimes()
 {
+       struct rusage ruch;
 
        time(&time0);
 
        time(&time0);
-#ifdef VMUNIX
-       vtimes(&vm0, 0);
-#else
-       times(&times0);
-#endif
+       getrusage(RUSAGE_SELF, &ru0);
+       getrusage(RUSAGE_CHILDREN, &ruch);
+       ruadd(&ru0, &ruch);
 }
 
 /*
 }
 
 /*
@@ -30,20 +25,13 @@ settimes()
 dotime()
 {
        time_t timedol;
 dotime()
 {
        time_t timedol;
-#ifdef VMUNIX
-       struct vtimes vm1, vmch;
-
-       vtimes(&vm1, &vmch);
-       vmsadd(&vm1, &vmch);
-#endif
+       struct rusage ru1, ruch;
 
 
+       getrusage(RUSAGE_SELF, &ru1);
+       getrusage(RUSAGE_CHILDREN, &ruch);
+       ruadd(&ru1, &ruch);
        time(&timedol);
        time(&timedol);
-#ifdef VMUNIX
-       pvtimes(&vm0, &vm1, timedol - time0);
-#else
-       times(&timesdol);
-       ptimes(timedol - time0, &times0, &timesdol);
-#endif
+       prusage(&ru0, &ru1, timedol - time0);
 }
 
 /*
 }
 
 /*
@@ -70,44 +58,32 @@ donice(v)
        }
 }
 
        }
 }
 
-#ifndef VMUNIX
-ptimes(utime, stime, etime)
-       register time_t utime, stime, etime;
-{
-
-       p60ths(utime);
-       printf("u ");
-       p60ths(stime);
-       printf("s ");
-       psecs(etime);
-       printf(" %d%%\n", (int) (100 * (utime+stime) /
-               (60 * (etime ? etime : 1))));
-}
-
-#else
-vmsadd(vp, wp)
-       register struct vtimes *vp, *wp;
+ruadd(ru, ru2)
+       register struct rusage *ru, *ru2;
 {
 {
-
-       vp->vm_utime += wp->vm_utime;
-       vp->vm_stime += wp->vm_stime;
-       vp->vm_nswap += wp->vm_nswap;
-       vp->vm_idsrss += wp->vm_idsrss;
-       vp->vm_ixrss += wp->vm_ixrss;
-       if (vp->vm_maxrss < wp->vm_maxrss)
-               vp->vm_maxrss = wp->vm_maxrss;
-       vp->vm_majflt += wp->vm_majflt;
-       vp->vm_minflt += wp->vm_minflt;
-       vp->vm_inblk += wp->vm_inblk;
-       vp->vm_oublk += wp->vm_oublk;
+       register long *lp, *lp2;
+       register int cnt;
+
+       tvadd(&ru->ru_utime, &ru2->ru_utime);
+       tvadd(&ru->ru_stime, &ru2->ru_stime);
+       if (ru2->ru_maxrss > ru->ru_maxrss)
+               ru->ru_maxrss = ru2->ru_maxrss;
+       cnt = &ru->ru_last - &ru->ru_first + 1;
+       lp = &ru->ru_first; lp2 = &ru2->ru_first;
+       do
+               *lp++ += *lp2++;
+       while (--cnt > 0);
 }
 
 }
 
-pvtimes(v0, v1, sec)
-       register struct vtimes *v0, *v1;
+prusage(r0, r1, sec)
+       register struct rusage *r0, *r1;
        time_t sec;
 {
        register time_t t =
        time_t sec;
 {
        register time_t t =
-           (v1->vm_utime-v0->vm_utime)+(v1->vm_stime-v0->vm_stime);
+           (r1->ru_utime.tv_sec-r0->ru_utime.tv_sec)*100+
+           (r1->ru_utime.tv_usec-r0->ru_utime.tv_usec)/10000+
+           (r1->ru_stime.tv_sec-r0->ru_stime.tv_sec)*100+
+           (r1->ru_stime.tv_usec-r0->ru_stime.tv_usec)/10000;
        register char *cp;
        register int i;
        register struct varent *vp = adrof("time");
        register char *cp;
        register int i;
        register struct varent *vp = adrof("time");
@@ -121,11 +97,11 @@ pvtimes(v0, v1, sec)
        else if (cp[1]) switch(*++cp) {
 
        case 'U':
        else if (cp[1]) switch(*++cp) {
 
        case 'U':
-               p60ths(v1->vm_utime - v0->vm_utime);
+               pdeltat(&r1->ru_utime, &r0->ru_utime);
                break;
 
        case 'S':
                break;
 
        case 'S':
-               p60ths(v1->vm_stime - v0->vm_stime);
+               pdeltat(&r1->ru_stime, &r0->ru_stime);
                break;
 
        case 'E':
                break;
 
        case 'E':
@@ -133,48 +109,77 @@ pvtimes(v0, v1, sec)
                break;
 
        case 'P':
                break;
 
        case 'P':
-               printf("%d%%", (int) ((100 * t) / (60 * (sec ? sec : 1))));
+               printf("%d%%", (int) (t / ((sec ? sec : 1))));
                break;
 
        case 'W':
                break;
 
        case 'W':
-               i = v1->vm_nswap - v0->vm_nswap;
+               i = r1->ru_nswap - r0->ru_nswap;
                printf("%d", i);
                break;
 
        case 'X':
                printf("%d", i);
                break;
 
        case 'X':
-               printf("%d", t == 0 ? 0 : (v1->vm_ixrss-v0->vm_ixrss)/(2*t));
+               printf("%d", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t);
                break;
 
        case 'D':
                break;
 
        case 'D':
-               printf("%d", t == 0 ? 0 : (v1->vm_idsrss-v0->vm_idsrss)/(2*t));
+               printf("%d", t == 0 ? 0 :
+                   (r1->ru_idrss+r1->ru_isrss-(r0->ru_idrss+r0->ru_isrss))/t);
                break;
 
        case 'K':
                break;
 
        case 'K':
-               printf("%d", t == 0 ? 0 : ((v1->vm_ixrss+v1->vm_idsrss) -
-                  (v0->vm_ixrss+v0->vm_idsrss))/(2*t));
+               printf("%d", t == 0 ? 0 :
+                   ((r1->ru_ixrss+r1->ru_isrss+r1->ru_idrss) -
+                   (r0->ru_ixrss+r0->ru_idrss+r0->ru_isrss))/t);
                break;
 
        case 'M':
                break;
 
        case 'M':
-               printf("%d", v1->vm_maxrss/2);
+               printf("%d", r1->ru_maxrss/2);
                break;
 
        case 'F':
                break;
 
        case 'F':
-               printf("%d", v1->vm_majflt-v0->vm_majflt);
+               printf("%d", r1->ru_majflt-r0->ru_majflt);
                break;
 
        case 'R':
                break;
 
        case 'R':
-               printf("%d", v1->vm_minflt-v0->vm_minflt);
+               printf("%d", r1->ru_minflt-r0->ru_minflt);
                break;
 
        case 'I':
                break;
 
        case 'I':
-               printf("%d", v1->vm_inblk-v0->vm_inblk);
+               printf("%d", r1->ru_inblock-r0->ru_inblock);
                break;
 
        case 'O':
                break;
 
        case 'O':
-               printf("%d", v1->vm_oublk-v0->vm_oublk);
+               printf("%d", r1->ru_oublock-r0->ru_oublock);
                break;
                break;
-
        }
        putchar('\n');
 }
        }
        putchar('\n');
 }
-#endif
+
+pdeltat(t1, t0)
+       struct timeval *t1, *t0;
+{
+       struct timeval td;
+
+       tvsub(&td, t1, t0);
+       printf("%d.%01d", td.tv_sec, td.tv_usec/100000);
+}
+
+tvadd(tsum, t0)
+       struct timeval *tsum, *t0;
+{
+
+       tsum->tv_sec += t0->tv_sec;
+       tsum->tv_usec += t0->tv_usec;
+       if (tsum->tv_usec > 1000000)
+               tsum->tv_sec++, tsum->tv_usec -= 1000000;
+}
+
+tvsub(tdiff, t1, t0)
+       struct timeval *tdiff, *t1, *t0;
+{
+
+       tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
+       tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
+       if (tdiff->tv_usec < 0)
+               tdiff->tv_sec--, tdiff->tv_usec += 1000000;
+}