added lwes-filter-listener
[lwes.git] / src / lwes_time_functions.c
blob8afe3a8818472e4c4b91d805f570352247c5263b
1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
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., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
20 #include "lwes_time_functions.h"
22 #if HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #if HAVE_EXTERNAL_GETTIMEOFDAY
27 #include EXTERNAL_GETTIMEOFDAY_HEADER
28 #endif
30 #ifndef GETTIMEOFDAY
31 #define GETTIMEOFDAY(t,tz) gettimeofday(t,tz)
32 #endif
35 LWES_INT_64 currentTimeMillisLongLong(void)
37 struct timeval t;
39 /* gettimeofday should ALWAYS return a value since the only possible error
40 * according to the FreeBSD and Linux man pages is EFAULT if you access
41 * invalid memory, this memory is on the stack so better be valid or we
42 * have bigger problems
44 GETTIMEOFDAY(&t,0);
46 return ((((LWES_INT_64)t.tv_sec)*((LWES_INT_64)1000)) +
47 (LWES_INT_64)(t.tv_usec/1000));
50 void convertUnixLongLongTimeToTimeval(LWES_INT_64 timestamp, struct timeval *t)
52 t->tv_sec = (long)(timestamp/1000);
53 t->tv_usec = (long)((timestamp%1000)*1000);