# HG changeset patch # User Timo Sirainen # Date 1218135940 14400 # Node ID bbfbc84f795cd40de15982105a7ce8ca7caf5fe1 # Parent 8a068f879cd12cd86a04621e0ce6fecfaa57e879 Added clock_gettime() compatibility function for systems without it. 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 @@ 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 #include #include +#include #ifdef HAVE_INTTYPES_H # include /* for strtoimax() and strtoumax() */ #endif @@ -276,3 +277,19 @@ 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 @@ -199,6 +199,14 @@ int my_vsnprintf(char *str, size_t size, const char *format, va_list ap); #endif +#ifndef HAVE_CLOCK_GETTIME +# include +# 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, use our own instead if really needed */ #define i_toupper(x) ((char) toupper((int) (unsigned char) (x)))