Require AC_HEADER_TIME rather than simply using it.
[gnulib.git] / m4 / nanosleep.m4
index e4b6341..1d15a73 100644 (file)
@@ -1,15 +1,31 @@
-#serial 1
+#serial 3
 
 dnl From Jim Meyering.
-dnl FIXME
+dnl Check for the nanosleep function.
+dnl If not found, use the supplied replacement.
 dnl
 
 AC_DEFUN(jm_FUNC_NANOSLEEP,
 [
+ # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
+ # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
+ AC_SEARCH_LIBS(nanosleep, [rt posix4])
+
  AC_CACHE_CHECK([whether nanosleep works],
   jm_cv_func_nanosleep_works,
-  [AC_TRY_RUN([
-#   include <time.h>
+  [
+   AC_REQUIRE([AC_HEADER_TIME])
+   AC_TRY_RUN([
+#   if TIME_WITH_SYS_TIME
+#    include <sys/time.h>
+#    include <time.h>
+#   else
+#    if HAVE_SYS_TIME_H
+#     include <sys/time.h>
+#    else
+#     include <time.h>
+#    endif
+#   endif
 
     int
     main ()
@@ -17,7 +33,7 @@ AC_DEFUN(jm_FUNC_NANOSLEEP,
       struct timespec ts_sleep, ts_remaining;
       ts_sleep.tv_sec = 0;
       ts_sleep.tv_nsec = 1;
-      exit (nanosleep (&ts_sleep, &ts_remaining) == 0 ? 1 : 0);
+      exit (nanosleep (&ts_sleep, &ts_remaining) == 0 ? 0 : 1);
     }
          ],
         jm_cv_func_nanosleep_works=yes,