Переглянути джерело

cdp: keep the ser_clock_gettime() inside the module

- some oses want librt for it
Daniel-Constantin Mierla 9 роки тому
батько
коміт
ab0a437db0
1 змінених файлів з 25 додано та 1 видалено
  1. 25 1
      modules/cdp/routing.c

+ 25 - 1
modules/cdp/routing.c

@@ -34,7 +34,10 @@
  *
  */
 
-#include "../../ser_time.h"
+#ifdef __OS_darwin
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
 
 #include "routing.h"
 #include "config.h"
@@ -47,6 +50,27 @@
 extern dp_config *config; /**< Configuration for this diameter peer 	*/
 int gcount = 0;
 
+/**
+ * portable implementation for clock_gettime(CLOCK_REALTIME, ts)
+ */
+int ser_clock_gettime(struct timespec *ts)
+{
+#ifdef __OS_darwin
+	clock_serv_t cclock;
+	mach_timespec_t mts;
+
+	/* OS X does not have clock_gettime, use clock_get_time */
+	host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+	clock_get_time(cclock, &mts);
+	mach_port_deallocate(mach_task_self(), cclock);
+	ts->tv_sec = mts.tv_sec;
+	ts->tv_nsec = mts.tv_nsec;
+	return 0;
+#else
+	return clock_gettime(CLOCK_REALTIME, ts);
+#endif
+}
+
 /**
  * Returns if the peer advertised support for an Application ID
  * @param p - the peer to check