and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osip2 / osip_time.c
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3   Copyright (C) 2001,2002,2003  Aymeric MOIZARD jack@atosc.org
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10   This library 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 GNU
13   Lesser General Public License for more details.
14   
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 #include <osip2/internal.h>
21 #include <osip2/osip.h>
22
23 #include "fsm.h"
24
25 void
26 add_gettimeofday (struct timeval *atv, int ms)
27 {
28   int m;
29   atv->tv_usec += ms * 1000;
30   m = atv->tv_usec / 1000000;
31   atv->tv_usec = atv->tv_usec % 1000000;
32   atv->tv_sec += m;
33 }
34
35 void
36 min_timercmp (struct timeval *tv1, struct timeval *tv2)
37 {
38   if (tv2->tv_sec == -1)
39     return;
40   if (timercmp (tv1, tv2, >))
41     {
42       /* replace tv1 with tv2 info */
43       tv1->tv_sec = tv2->tv_sec;
44       tv1->tv_usec = tv2->tv_usec;
45     }
46 }
47
48 #ifdef WIN32
49
50 #include <time.h>
51 #include <sys/timeb.h>
52
53 int
54 gettimeofday (struct timeval *tp, void *tz)
55 {
56   struct _timeb timebuffer;
57
58   _ftime (&timebuffer);
59   tp->tv_sec = timebuffer.time;
60   tp->tv_usec = timebuffer.millitm * 1000;
61   return 0;
62 }
63
64 #endif