File: func_time.c

package info (click to toggle)
arpalert 2.0.12-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 3,508 kB
  • sloc: ansic: 4,452; sh: 517; makefile: 116; perl: 35
file content (31 lines) | stat: -rw-r--r-- 707 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright (c) 2005-2010 Thierry FOURNIER
 * $Id: func_time.c 690 2008-03-31 18:36:43Z  $
 *
 */

#include <sys/time.h>

/* compare t1 to t2
 * si t1 > t2 => 1
 * si t1 = t2 => 0
 * si t1 < t2 =>-1
 */
int time_comp(struct timeval *t1, struct timeval *t2){
	if(t1->tv_sec == t2->tv_sec && t1->tv_usec == t2->tv_usec)
		return 0;
	else if((t1->tv_sec == t2->tv_sec && t1->tv_usec > t2->tv_usec) ||
	        (t1->tv_sec > t2->tv_sec))
		return 1;
	else
		return -1;
}

void time_sous(struct timeval *t1, struct timeval *t2, struct timeval *res){
	res->tv_sec = t1->tv_sec - t2->tv_sec;
	res->tv_usec = t1->tv_usec - t2->tv_usec;
	if(res->tv_usec < 0){
		res->tv_sec -= 1;
		res->tv_usec += 1000000;
	}
}