BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / ktrace / ktrace / subr.c
CommitLineData
1c15e888
C
1/*-
2 * Copyright (c) 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted provided
6 * that: (1) source distributions retain this entire copyright notice and
7 * comment, and (2) distributions including binaries display the following
8 * acknowledgement: ``This product includes software developed by the
9 * University of California, Berkeley and its contributors'' in the
10 * documentation or other materials provided with the distribution and in
11 * all advertising materials mentioning features or use of this software.
12 * Neither the name of the University nor the names of its contributors may
13 * be used to endorse or promote products derived from this software without
14 * specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20#ifndef lint
21static char sccsid[] = "@(#)subr.c 1.2 (Berkeley) 6/29/90";
22#endif /* not lint */
23
24#include "ktrace.h"
25#include <sys/time.h>
26
27getpoints(s)
28 char *s;
29{
30 int facs = 0;
31
32 while (*s) {
33 switch(*s) {
34 case 'c':
35 facs |= KTRFAC_SYSCALL | KTRFAC_SYSRET;
36 break;
37 case 'n':
38 facs |= KTRFAC_NAMEI;
39 break;
40 case 'i':
41 facs |= KTRFAC_GENIO;
42 break;
43 case 's':
44 facs |= KTRFAC_PSIG;
45 break;
46 default:
47 return (-1);
48 }
49 s++;
50 }
51 return (facs);
52}
53
54timevaladd(t1, t2)
55 struct timeval *t1, *t2;
56{
57
58 t1->tv_sec += t2->tv_sec;
59 t1->tv_usec += t2->tv_usec;
60 timevalfix(t1);
61}
62
63timevalsub(t1, t2)
64 struct timeval *t1, *t2;
65{
66
67 t1->tv_sec -= t2->tv_sec;
68 t1->tv_usec -= t2->tv_usec;
69 timevalfix(t1);
70}
71
72timevalfix(t1)
73 struct timeval *t1;
74{
75
76 if (t1->tv_usec < 0) {
77 t1->tv_sec--;
78 t1->tv_usec += 1000000;
79 }
80 if (t1->tv_usec >= 1000000) {
81 t1->tv_sec++;
82 t1->tv_usec -= 1000000;
83 }
84}