[strongSwan-dev] [PATCH 2/2] If HAVE_CLOCK_GETTIME is not defined, define an alternate to clock_gettime().

J. Tang tang at jtang.org
Mon Nov 7 04:43:55 CET 2011


If HAVE_CLOCK_GETTIME is not defined, call gettimeofday() instead.

Signed-off-by: J. Tang <tang at jtang.org>
---
  src/libstrongswan/utils.c |   11 +++++++++++
  src/libstrongswan/utils.h |    6 ++++++
  2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c
index 2fe7f65..9be530f 100644
--- a/src/libstrongswan/utils.c
+++ b/src/libstrongswan/utils.c
@@ -468,3 +468,14 @@ int mem_printf_hook(char *dst, size_t dstlen,
  	}
  	return written;
  }
+
+#ifndef HAVE_CLOCK_GETTIME
+
+void clock_gettime(int clk_id __attribute__((unused)), struct  
timespec *tp) {
+	struct timeval tv = {0, 0};
+	gettimeofday(&tv, NULL);
+	tp->tv_sec = tv.tv_sec;
+	tp->tv_nsec = tv.tv_usec * 1000;
+}
+
+#endif /* HAVE_CLOCK_GETTIME */
diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h
index 0f06fec..54ee2c3 100644
--- a/src/libstrongswan/utils.h
+++ b/src/libstrongswan/utils.h
@@ -574,4 +574,10 @@ int time_delta_printf_hook(char *dst, size_t  
len, printf_hook_spec_t *spec,
  int mem_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
  					const void *const *args);

+#ifndef HAVE_CLOCK_GETTIME
+#define CLOCK_THREAD_CPUTIME_ID 0
+void clock_gettime(int clk_id, struct timespec *tp);
+
+#endif /* HAVE_CLOCK_GETTIME */
+
  #endif /** UTILS_H_ @}*/
-- 
1.7.3.2





More information about the Dev mailing list