Commit f6c337bc authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Add replacement for clock_gettime (for Mac OS) -- ticket #38

parent d96ad2f9
......@@ -71,20 +71,24 @@ INCLUDE(FindThreads)
SET(CMAKE_THREAD_LIBS_INIT ${CMAKE_THREAD_LIBS_INIT} PARENT_SCOPE)
# clock_gettime
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
IF (HAVE_CLOCK_GETTIME)
SET(HAVE_CLOCK_GETTIME "")
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_NATIVE_CLOCK_GETTIME)
IF (HAVE_NATIVE_CLOCK_GETTIME)
SET(CLOCK_GETTIME_LIBS "")
ELSE (HAVE_CLOCK_GETTIME)
SET(HAVE_CLOCK_GETTIME 1)
ELSE (HAVE_NATIVE_CLOCK_GETTIME)
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_LIBRT)
IF (HAVE_LIBRT)
SET(CLOCK_GETTIME_LIBS "-lrt")
SET(HAVE_CLOCK_GETTIME 1)
ELSE (HAVE_LIBRT)
CHECK_LIBRARY_EXISTS (posix4 clock_gettime "" HAVE_LIBPOSIX4)
IF (HAVE_LIBPOSIX4)
SET(CLOCK_GETTIME_LIBS "-lposix4")
SET(HAVE_CLOCK_GETTIME 1)
ENDIF (HAVE_LIBPOSIX4)
ENDIF (HAVE_LIBRT)
ENDIF (HAVE_CLOCK_GETTIME)
ENDIF (HAVE_NATIVE_CLOCK_GETTIME)
SET(CLOCK_GETTIME_LIBS ${CLOCK_GETTIME_LIBS} PARENT_SCOPE)
# dlopen and dlclose: CMAKE_DL_LIBS
......
......@@ -41,6 +41,7 @@
#cmakedefine HAVE_MALLOC_H
#cmakedefine HAVE_SIGNALENT_H
#cmakedefine HAVE_AI_ADDRCONFIG
#cmakedefine HAVE_CLOCK_GETTIME
#cmakedefine HOST_BIG_ENDIAN @HOST_BIG_ENDIAN@
......
......@@ -602,6 +602,17 @@ int fd_breakhere(void);
#define CONSTSTRLEN( str ) (sizeof(str) - 1)
/*============================================================*/
/* PORTABILITY */
/*============================================================*/
#ifndef HAVE_CLOCK_GETTIME
#define CLOCK_REALTIME 0
#include <sys/time.h>
int clock_gettime(int clk_id, struct timespec* ts);
#endif /* HAVE_CLOCK_GETTIME */
/*============================================================*/
/* BINARY STRINGS */
/*============================================================*/
......
......@@ -13,6 +13,7 @@ SET(LFDPROTO_SRC
messages.c
msg_log.c
ostr.c
portability.c
rt_data.c
sessions.c
)
......
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@freediameter.net> *
* *
* Copyright (c) 2011, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
#include "fdproto-internal.h"
/* Replacement for clock_gettime for the Mac OS */
#ifndef HAVE_CLOCK_GETTIME
int clock_gettime(int clk_id, struct timespec* ts)
{
struct timeval tv;
gettimeofday (&tv, NULL);
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;
}
#endif /* HAVE_CLOCK_GETTIME */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment