]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added clock_gettime() compatibility function for systems without it.
authorTimo Sirainen <tss@iki.fi>
Thu, 7 Aug 2008 19:05:40 +0000 (15:05 -0400)
committerTimo Sirainen <tss@iki.fi>
Thu, 7 Aug 2008 19:05:40 +0000 (15:05 -0400)
--HG--
branch : HEAD

configure.in
src/lib/compat.c
src/lib/compat.h

index d84bb5726a2e1c15e960415ce181304608829639..7066a69898178554398ddc23d37c0e2539ce5836 100644 (file)
@@ -443,7 +443,7 @@ AC_CHECK_FUNCS(fcntl flock lockf inet_aton sigaction getpagesize madvise \
               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])
index 192d300481f51eb87b75898750b5afc5ffca77f5..e759741f4abc2b7bc40db81c98ffa673fc965576 100644 (file)
@@ -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, const char *format, va_list ap)
        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
index 9c96491532177ede1a1f98440fb90bafee9fbdb1..9e6792bdf10b05b4fc17141496465ee11d77c241 100644 (file)
@@ -199,6 +199,14 @@ unsigned long long int my_strtoll(const char *nptr, char **endptr, int base);
 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)))