]> Savannah Git Hosting - gnulib.git/commitdiff
nanosleep: Work around bug on newer 32-bit mingw.
authorBruno Haible <bruno@clisp.org>
Sun, 4 Sep 2022 11:26:19 +0000 (13:26 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 4 Sep 2022 11:36:18 +0000 (13:36 +0200)
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Test for 32-bit mingw bug.
* tests/test-nanosleep.c (main): Add another test.
* doc/posix-functions/nanosleep.texi: Mention the mingw bug.

ChangeLog
doc/posix-functions/nanosleep.texi
m4/nanosleep.m4
tests/test-nanosleep.c

index f8ec7e518e8aaa407d9d4b2c876a8147d4f7aa1a..11bbd8f721edf48892cbb8a640d507945d53f5ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-04  Bruno Haible  <bruno@clisp.org>
+
+       nanosleep: Work around bug on newer 32-bit mingw.
+       * m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Test for 32-bit mingw bug.
+       * tests/test-nanosleep.c (main): Add another test.
+       * doc/posix-functions/nanosleep.texi: Mention the mingw bug.
+
 2022-09-03  Bruno Haible  <bruno@clisp.org>
 
        fmal: Work around glibc 2.17 bug on x86_64.
index 8ede0b01f90a34650b829b9f466972e48a1e8111..be54aef571969a26a654270dfe5e83f1caf018f6 100644 (file)
@@ -18,6 +18,10 @@ Linux 64-bit, Solaris 64-bit.
 @item
 This function cannot sleep longer than 49.7 days on some platforms:
 Cygwin 1.5.x.
+@item
+This function does not fail when passed a negative nanosecond value on some
+platforms:
+newer 32-bit mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 1964b1ea47d9a4deec387933d94f6f6d5f4aa94f..dfe21f56d5c7257a8d2966cf0ccc1997620409af 100644 (file)
@@ -1,4 +1,4 @@
-# serial 41
+# serial 42
 
 dnl From Jim Meyering.
 dnl Check for the nanosleep function.
@@ -100,15 +100,22 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
             #else /* A simpler test for native Windows.  */
             if (nanosleep (&ts_sleep, &ts_remaining) < 0)
               return 3;
+            /* Test for 32-bit mingw bug: negative nanosecond values do not
+               cause failure.  */
+            ts_sleep.tv_sec = 1;
+            ts_sleep.tv_nsec = -1;
+            if (nanosleep (&ts_sleep, &ts_remaining) != -1)
+              return 7;
             #endif
             return 0;
           }]])],
        [gl_cv_func_nanosleep=yes],
-       [case $? in dnl (
-        4|5|6) gl_cv_func_nanosleep='no (mishandles large arguments)';; dnl (
-        *)   gl_cv_func_nanosleep=no;;
+       [case $? in
+        4|5|6) gl_cv_func_nanosleep='no (mishandles large arguments)' ;;
+        7)     gl_cv_func_nanosleep='no (mishandles negative tv_nsec)' ;;
+        *)     gl_cv_func_nanosleep=no ;;
         esac],
-       [case "$host_os" in dnl ((
+       [case "$host_os" in
           linux*) # Guess it halfway works when the kernel is Linux.
             gl_cv_func_nanosleep='guessing no (mishandles large arguments)' ;;
           mingw*) # Guess no on native Windows.
index e7edeffc0e92ab78b043bf6eabe909504356d315..c208161559a30609d2f4adf636af15713988496f 100644 (file)
@@ -43,16 +43,27 @@ main (void)
 {
   struct timespec ts;
 
+  /* Check that negative nanosecond values cause failure.  */
+  ts.tv_sec = 1;
+  ts.tv_nsec = -1;
+  errno = 0;
+  ASSERT (nanosleep (&ts, NULL) == -1);
+  ASSERT (errno == EINVAL);
+
   ts.tv_sec = 1000;
   ts.tv_nsec = -1;
   errno = 0;
   ASSERT (nanosleep (&ts, NULL) == -1);
   ASSERT (errno == EINVAL);
+
+  /* Check that too large nanosecond values cause failure.  */
+  ts.tv_sec = 1000;
   ts.tv_nsec = 1000000000;
   errno = 0;
   ASSERT (nanosleep (&ts, NULL) == -1);
   ASSERT (errno == EINVAL);
 
+  /* Check successful call.  */
   ts.tv_sec = 0;
   ts.tv_nsec = 1;
   ASSERT (nanosleep (&ts, &ts) == 0);