Darwin doesn't support clock_gettime() but has _POSIX_MONOTONIC_CLOCK defined
so use a more strict check with HAVE_CLOCK_GETTIME.

This fixes the following compilation error:

  java_lang_VMSystem.c: In function ‘Java_java_lang_VMSystem_nanoTime’:
  java_lang_VMSystem.c:148: warning: implicit declaration of function 
‘clock_gettime’
  java_lang_VMSystem.c:148: error: ‘CLOCK_MONOTONIC’ undeclared (first use in 
this function)
  java_lang_VMSystem.c:148: error: (Each undeclared identifier is reported only 
once
  java_lang_VMSystem.c:148: error: for each function it appears in.)

Signed-off-by: Pekka Enberg <penb...@kernel.org>
---
v1 -> v2: Use HAVE_CLOCK_GETTIME

 configure.ac                              |    4 +++-
 native/jni/java-lang/java_lang_VMSystem.c |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index f9105e9..a106e11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -440,13 +440,15 @@ if test "x${COMPILE_JNI}" = xyes; then
   AC_EGREP_HEADER(u_int32_t, sys/types.h, AC_DEFINE(HAVE_BSD_INT32_DEFINED, 1, 
[Define to 1 if you have BSD u_int32_t]))
   AC_EGREP_HEADER(u_int32_t, sys/config.h, AC_DEFINE(HAVE_BSD_INT32_DEFINED, 
1, [Define to 1 if you have BSD u_int32_t]))
 
+  AC_SEARCH_LIBS([clock_gettime], [rt])
   AC_SEARCH_LIBS([inet_pton],[nsl])
   AC_CHECK_LIB([socket], [gethostname]) 
+
   AC_CHECK_FUNCS([ftruncate fsync select \
                  gethostname socket strerror fork pipe execve open close \
                  lseek fstat read readv write writev htonl memset htons 
connect \
                  getsockname getpeername bind listen accept \
-                 recvfrom send sendto setsockopt getsockopt time mktime \
+                 recvfrom send sendto setsockopt getsockopt time mktime 
clock_gettime \
                  gethostbyname_r localtime_r \
                  strerror_r \
                   fcntl \
diff --git a/native/jni/java-lang/java_lang_VMSystem.c 
b/native/jni/java-lang/java_lang_VMSystem.c
index 047c2b3..f623857 100644
--- a/native/jni/java-lang/java_lang_VMSystem.c
+++ b/native/jni/java-lang/java_lang_VMSystem.c
@@ -141,7 +141,7 @@ Java_java_lang_VMSystem_nanoTime
   (JNIEnv * env,
    jclass thisClass __attribute__ ((__unused__)))
 {
-#ifdef _POSIX_MONOTONIC_CLOCK
+#if defined(HAVE_CLOCK_GETTIME) && defined(_POSIX_MONOTONIC_CLOCK)
   jlong result;
   struct timespec tp;
 
-- 
1.7.4.1


Reply via email to