Use clock_gettime if it is available.
[crypto.git] / lib / silcutil / unix / silcunixutil.c
index 4b37ea5e769c65e59dd12656130e675010ad295d..50e01d07b92282fbb31db4980053741b6cc2ee9b 100644 (file)
@@ -69,7 +69,15 @@ char *silc_get_real_name()
 
 int silc_gettimeofday(struct timeval *p)
 {
+#if defined(HAVE_CLOCK_GETTIME)
+  struct timespec tp;
+  clock_gettime(CLOCK_REALTIME, &tp);
+  p->tv_sec = tp.tv_sec;
+  p->tv_usec = tp.tv_nsec / 1000;
+  return 0;
+#else
   return gettimeofday(p, NULL);
+#endif /* HAVE_CLOCK_GETTIME */
 }
 
 int silc_file_set_nonblock(int fd)