1 /* $Header: /home/yav/catty/fkiss/RCS/timer.c,v 1.4 2000/08/24 02:25:38 yav Exp $
2 * Time control routine
3 * written by yav <yav@bigfoot.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <X11/Xos.h>
21 #include <stdio.h>
22 #include "config.h"
23
24 #include "timer.h"
25
26 char id_timer[] = "$Id: timer.c,v 1.4 2000/08/24 02:25:38 yav Exp $";
27
diff_time(p1,p0)28 long diff_time(p1, p0)
29 struct TMV *p1;
30 struct TMV *p0;
31 {
32 struct TMV tm;
33
34 tm.tv_sec = p1->tv_sec - p0->tv_sec;
35 tm.tv_usec = p1->tv_usec - p0->tv_usec;
36 if (tm.tv_usec < 0) {
37 tm.tv_usec += 1000000;
38 tm.tv_sec--;
39 }
40 if (tm.tv_sec > 86400L) /* 24 hour */
41 tm.tv_sec = 86400L;
42 return tm.tv_sec * 1000 + tm.tv_usec / 1000;
43 }
44
add_time(p,n)45 void add_time(p, n)
46 struct TMV *p;
47 long n;
48 {
49 p->tv_sec += n / 1000;
50 p->tv_usec += (n % 1000) * 1000;
51 if (p->tv_usec < 0) {
52 p->tv_usec += 1000000;
53 p->tv_sec--;
54 } else if (p->tv_usec >= 1000000) {
55 p->tv_usec -= 1000000;
56 p->tv_sec++;
57 }
58 }
59
60 /* End of file */
61