OpenCoverage

timeval.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/timeval.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* timeval.c - functions to perform operations on struct timevals */-
2-
3/* Copyright (C) 1999 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include <config.h>-
22-
23#if defined (HAVE_TIMEVAL)-
24-
25#include <sys/types.h>-
26#include <posixtime.h>-
27-
28#include <stdio.h>-
29-
30struct timeval *-
31difftimeval (d, t1, t2)-
32 struct timeval *d, *t1, *t2;-
33{-
34 d->tv_sec = t2->tv_sec - t1->tv_sec;-
35 d->tv_usec = t2->tv_usec - t1->tv_usec;-
36 if (d->tv_usec < 0)
d->tv_usec < 0Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
0-30
37 {-
38 d->tv_usec += 1000000;-
39 d->tv_sec -= 1;-
40 if (d->tv_sec < 0) /* ??? -- BSD/OS does this */
d->tv_sec < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
41 {-
42 d->tv_sec = 0;-
43 d->tv_usec = 0;-
44 }
never executed: end of block
0
45 }
never executed: end of block
0
46 return d;
executed 30 times by 1 test: return d;
Executed by:
  • Self test
30
47}-
48-
49struct timeval *-
50addtimeval (d, t1, t2)-
51 struct timeval *d, *t1, *t2;-
52{-
53 d->tv_sec = t1->tv_sec + t2->tv_sec;-
54 d->tv_usec = t1->tv_usec + t2->tv_usec;-
55 if (d->tv_usec >= 1000000)
d->tv_usec >= 1000000Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
56 {-
57 d->tv_usec -= 1000000;-
58 d->tv_sec += 1;-
59 }
never executed: end of block
0
60 return d;
executed 18 times by 1 test: return d;
Executed by:
  • Self test
18
61}-
62-
63/* Do "cpu = ((user + sys) * 10000) / real;" with timevals.-
64 Barely-tested code from Deven T. Corzine <deven@ties.org>. */-
65int-
66timeval_to_cpu (rt, ut, st)-
67 struct timeval *rt, *ut, *st; /* real, user, sys */-
68{-
69 struct timeval t1, t2;-
70 register int i;-
71-
72 addtimeval (&t1, ut, st);-
73 t2.tv_sec = rt->tv_sec;-
74 t2.tv_usec = rt->tv_usec;-
75-
76 for (i = 0; i < 6; i++)
i < 6Description
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-36
77 {-
78 if ((t1.tv_sec > 99999999) || (t2.tv_sec > 99999999))
(t1.tv_sec > 99999999)Description
TRUEnever evaluated
FALSEevaluated 36 times by 1 test
Evaluated by:
  • Self test
(t2.tv_sec > 99999999)Description
TRUEnever evaluated
FALSEevaluated 36 times by 1 test
Evaluated by:
  • Self test
0-36
79 break;
never executed: break;
0
80 t1.tv_sec *= 10;-
81 t1.tv_sec += t1.tv_usec / 100000;-
82 t1.tv_usec *= 10;-
83 t1.tv_usec %= 1000000;-
84 t2.tv_sec *= 10;-
85 t2.tv_sec += t2.tv_usec / 100000;-
86 t2.tv_usec *= 10;-
87 t2.tv_usec %= 1000000;-
88 }
executed 36 times by 1 test: end of block
Executed by:
  • Self test
36
89 for (i = 0; i < 4; i++)
i < 4Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-24
90 {-
91 if (t1.tv_sec < 100000000)
t1.tv_sec < 100000000Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-24
92 t1.tv_sec *= 10;
executed 24 times by 1 test: t1.tv_sec *= 10;
Executed by:
  • Self test
24
93 else-
94 t2.tv_sec /= 10;
never executed: t2.tv_sec /= 10;
0
95 }-
96-
97 return ((t2.tv_sec == 0) ? 0 : t1.tv_sec / t2.tv_sec);
executed 6 times by 1 test: return ((t2.tv_sec == 0) ? 0 : t1.tv_sec / t2.tv_sec);
Executed by:
  • Self test
6
98} -
99-
100/* Convert a pointer to a struct timeval to seconds and thousandths of a-
101 second, returning the values in *SP and *SFP, respectively. This does-
102 rounding on the fractional part, not just truncation to three places. */-
103void-
104timeval_to_secs (tvp, sp, sfp)-
105 struct timeval *tvp;-
106 time_t *sp;-
107 int *sfp;-
108{-
109 int rest;-
110-
111 *sp = tvp->tv_sec;-
112-
113 *sfp = tvp->tv_usec % 1000000; /* pretty much a no-op */-
114 rest = *sfp % 1000;-
115 *sfp = (*sfp * 1000) / 1000000;-
116 if (rest >= 500)
rest >= 500Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
117 *sfp += 1;
never executed: *sfp += 1;
0
118-
119 /* Sanity check */-
120 if (*sfp >= 1000)
*sfp >= 1000Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
121 {-
122 *sp += 1;-
123 *sfp -= 1000;-
124 }
never executed: end of block
0
125}
executed 18 times by 1 test: end of block
Executed by:
  • Self test
18
126 -
127/* Print the contents of a struct timeval * in a standard way to stdio-
128 stream FP. */-
129void-
130print_timeval (fp, tvp)-
131 FILE *fp;-
132 struct timeval *tvp;-
133{-
134 time_t timestamp;-
135 long minutes;-
136 int seconds, seconds_fraction;-
137-
138 timeval_to_secs (tvp, &timestamp, &seconds_fraction);-
139-
140 minutes = timestamp / 60;-
141 seconds = timestamp % 60;-
142-
143 fprintf (fp, "%ldm%d.%03ds", minutes, seconds, seconds_fraction);-
144}
never executed: end of block
0
145#endif /* HAVE_TIMEVAL */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2