Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8076:bbfbc84f795c HEAD
Added clock_gettime() compatibility function for systems without it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 07 Aug 2008 15:05:40 -0400 |
parents | 8a068f879cd1 |
children | 6d51328896d6 |
files | configure.in src/lib/compat.c src/lib/compat.h |
diffstat | 3 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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])
--- 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 @@ 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
--- 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 <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, use our own instead if really needed */ #define i_toupper(x) ((char) toupper((int) (unsigned char) (x)))