add license to distribution file
[lwes.git] / src / lwes_time_functions.c
blobaf2b5f3e09fb6a063733b2718494fa8666ed600b
1 /*======================================================================*
2 * Copyright (c) 2008, Yahoo! Inc. All rights reserved. *
3 * *
4 * Licensed under the New BSD License (the "License"); you may not use *
5 * this file except in compliance with the License. Unless required *
6 * by applicable law or agreed to in writing, software distributed *
7 * under the License is distributed on an "AS IS" BASIS, WITHOUT *
8 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
9 * See the License for the specific language governing permissions and *
10 * limitations under the License. See accompanying LICENSE file. *
11 *======================================================================*/
13 #include "lwes_time_functions.h"
15 #if HAVE_CONFIG_H
16 #include <config.h>
17 #endif
19 #if HAVE_EXTERNAL_GETTIMEOFDAY
20 #include EXTERNAL_GETTIMEOFDAY_HEADER
21 #endif
23 #ifndef GETTIMEOFDAY
24 #define GETTIMEOFDAY(t,tz) gettimeofday(t,tz)
25 #endif
28 LWES_INT_64 currentTimeMillisLongLong(void)
30 struct timeval t;
32 /* gettimeofday should ALWAYS return a value since the only possible error
33 * according to the FreeBSD and Linux man pages is EFAULT if you access
34 * invalid memory, this memory is on the stack so better be valid or we
35 * have bigger problems
37 GETTIMEOFDAY(&t,0);
39 return ((((LWES_INT_64)t.tv_sec)*((LWES_INT_64)1000)) +
40 (LWES_INT_64)(t.tv_usec/1000));
43 void convertUnixLongLongTimeToTimeval(LWES_INT_64 timestamp, struct timeval *t)
45 t->tv_sec = (long)(timestamp/1000);
46 t->tv_usec = (long)((timestamp%1000)*1000);