5xxx functions from nbdkit.
[libguestfs-talks.git] / 2020-frama-c / 5300-timeval.html
1 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
2 <link rel="stylesheet" href="style.css" type="text/css"/>
3 <script src="code.js" type="text/javascript"></script>
4
5 <h1>nbdkit tvdiff_usec</h1>
6
7 <pre class="code">
8   <span class="comment">/*@
9     predicate valid_timeval (struct timeval tv) =
10       tv.tv_sec >= 0 && tv.tv_usec >= 0 && tv.tv_usec < 1000000;
11     logic integer tv_to_microseconds (struct timeval tv) =
12       tv.tv_sec * 1000000 + tv.tv_usec;
13    */</span>
14
15   /* Return the number of µs (microseconds) in y - x. */
16   <span class="comment">/*@
17     requires \valid_read (x) && \valid_read (y);
18     requires valid_timeval (*x) && valid_timeval (*y);
19     ensures \result == tv_to_microseconds (*y) - tv_to_microseconds (*x);
20    */</span>
21   static inline int64_t
22   tvdiff_usec (const struct timeval *x, const struct timeval *y)
23   {
24     int64_t usec;
25
26     usec = (y->tv_sec - x->tv_sec) * 1000000;
27     usec += y->tv_usec - x->tv_usec;
28     return usec;
29   }
30 </pre>