Mercurial > hg > freeDiameter
changeset 836:da97a5aa7976
Add replacement for clock_gettime (for Mac OS) -- ticket #38
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Wed, 10 Oct 2012 13:34:30 +0200 |
parents | 885f5eb20b21 |
children | 1d2721778c7a |
files | include/freeDiameter/CMakeLists.txt include/freeDiameter/freeDiameter-host.h.in include/freeDiameter/libfdproto.h libfdproto/CMakeLists.txt libfdproto/portability.c |
diffstat | 5 files changed, 68 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/include/freeDiameter/CMakeLists.txt Sat Sep 29 14:35:03 2012 +0200 +++ b/include/freeDiameter/CMakeLists.txt Wed Oct 10 13:34:30 2012 +0200 @@ -71,20 +71,24 @@ 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
--- a/include/freeDiameter/freeDiameter-host.h.in Sat Sep 29 14:35:03 2012 +0200 +++ b/include/freeDiameter/freeDiameter-host.h.in Wed Oct 10 13:34:30 2012 +0200 @@ -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@
--- a/include/freeDiameter/libfdproto.h Sat Sep 29 14:35:03 2012 +0200 +++ b/include/freeDiameter/libfdproto.h Wed Oct 10 13:34:30 2012 +0200 @@ -603,6 +603,17 @@ /*============================================================*/ +/* 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 */ /*============================================================*/
--- a/libfdproto/CMakeLists.txt Sat Sep 29 14:35:03 2012 +0200 +++ b/libfdproto/CMakeLists.txt Wed Oct 10 13:34:30 2012 +0200 @@ -13,6 +13,7 @@ messages.c msg_log.c ostr.c + portability.c rt_data.c sessions.c )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfdproto/portability.c Wed Oct 10 13:34:30 2012 +0200 @@ -0,0 +1,47 @@ +/********************************************************************************************************* +* 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 */