dovecot-1.2: Added clock_gettime() compatibility function for sy...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 7 22:34:02 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/bbfbc84f795c
changeset: 8076:bbfbc84f795c
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 07 15:05:40 2008 -0400
description:
Added clock_gettime() compatibility function for systems without it.

diffstat:

3 files changed, 26 insertions(+), 1 deletion(-)
configure.in     |    2 +-
src/lib/compat.c |   17 +++++++++++++++++
src/lib/compat.h |    8 ++++++++

diffs (61 lines):

diff -r 8a068f879cd1 -r bbfbc84f795c configure.in
--- a/configure.in	Thu Aug 07 14:05:47 2008 -0400
+++ b/configure.in	Thu Aug 07 15:05:40 2008 -0400
@@ -443,7 +443,7 @@ AC_CHECK_FUNCS(fcntl flock lockf inet_at
 	       setrlimit setproctitle seteuid setreuid setegid setresgid \
 	       strtoull strtoll strtouq strtoq \
 	       setpriority quotactl getmntent kqueue kevent backtrace_symbols \
-	       walkcontext dirfd clearenv malloc_usable_size)
+	       walkcontext dirfd clearenv malloc_usable_size clock_gettime)
 
 dnl strtoimax and strtoumax are macros in HP-UX, so inttypes.h must be included
 AC_MSG_CHECKING([for strtoimax])
diff -r 8a068f879cd1 -r bbfbc84f795c src/lib/compat.c
--- a/src/lib/compat.c	Thu Aug 07 14:05:47 2008 -0400
+++ b/src/lib/compat.c	Thu Aug 07 15:05:40 2008 -0400
@@ -17,6 +17,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <syslog.h>
+#include <sys/time.h>
 #ifdef HAVE_INTTYPES_H
 #  include <inttypes.h> /* for strtoimax() and strtoumax() */
 #endif
@@ -276,3 +277,19 @@ int my_vsnprintf(char *str, size_t size,
 	i_panic("my_vsnprintf(): Output string too big");
 }
 #endif
+
+#ifndef HAVE_CLOCK_GETTIME
+int my_clock_gettime(int clk_id, struct timespec *tp)
+{
+	struct timeval tv;
+
+	i_assert(clk_id == CLOCK_REALTIME);
+
+	/* fallback to using microseconds */
+	if (gettimeofday(&tv, NULL) < 0)
+		return -1;
+	tp->tv_sec = tv.tv_sec;
+	tp->tv_nsec = tv.tv_usec * 1000;
+	return 0;
+}
+#endif
diff -r 8a068f879cd1 -r bbfbc84f795c src/lib/compat.h
--- a/src/lib/compat.h	Thu Aug 07 14:05:47 2008 -0400
+++ b/src/lib/compat.h	Thu Aug 07 15:05:40 2008 -0400
@@ -197,6 +197,14 @@ unsigned long long int my_strtoll(const 
 #  include <stdio.h>
 #  define vsnprintf my_vsnprintf
 int my_vsnprintf(char *str, size_t size, const char *format, va_list ap);
+#endif
+
+#ifndef HAVE_CLOCK_GETTIME
+#  include <time.h>
+#  undef CLOCK_REALTIME
+#  define CLOCK_REALTIME 1
+#  define clock_gettime my_clock_gettime
+int my_clock_gettime(int clk_id, struct timespec *tp);
 #endif
 
 /* ctype.h isn't safe with signed chars,


More information about the dovecot-cvs mailing list