* New upstream release.
[debian/cdck.git] / src / lib_time.c
1 /*
2  * $RCSfile: lib_time.c,v $
3  * $Author: swaj $
4  * $Revision: 1.3 $
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <sys/time.h>
15 #include <sys/time.h>
16 #include <unistd.h>
17
18 #include "defines.h"
19 #include "debugging.h"
20 #include "cdck_main.h"
21 #include "lib_time.h"
22
23 //#ifndef 
24
25
26 void time_substract_timeval (struct timeval *t2, struct timeval *t1, struct timeval *td)
27 {
28         if (!t2 || !t1 || !td) {
29                 // printf("null arg");
30                 return;
31         }
32
33         td->tv_sec = t2->tv_sec - t1->tv_sec;
34
35         if (t2->tv_usec < t1->tv_usec) {
36                 td->tv_sec--;
37                 td->tv_usec = (1000000 + t2->tv_usec) - t1->tv_usec;
38         } else {
39                 td->tv_usec = t2->tv_usec - t1->tv_usec;
40         } 
41 }
42
43 int time_get_time_usec (struct timeval *tv)
44 {
45         if (! tv)
46                 return TV_INVALID;
47
48         if (tv->tv_sec >= TV_INT_MAX_SEC)
49                 return TV_TOO_BIG;
50
51         return (tv->tv_sec * 1000000 + tv->tv_usec); 
52 }
53
54
55 float time_get_time_ms (struct timeval *tv)
56 {
57         if (!tv)
58                 return 0;
59
60         return ( (double)tv->tv_sec * 1000.0 + (double)tv->tv_usec / 1000.0);
61
62
63
64
65 /*
66  * __END__
67  */