]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2004-12-29 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@gnu.org>
Wed, 16 Feb 2005 09:26:38 +0000 (09:26 +0000)
committerRoland McGrath <roland@gnu.org>
Wed, 16 Feb 2005 09:26:38 +0000 (09:26 +0000)
[BZ #626]
* sysdeps/unix/alarm.c (alarm): Round return value to nearest rather
than always up; when nearest is zero, round up to one.

sysdeps/unix/alarm.c

index ae77782c5471d6aed53d6728ef80065f186f8843..dafada76b588219f9a27db3b1e27ebaaf58bd7a4 100644 (file)
@@ -41,7 +41,10 @@ alarm (seconds)
     return 0;
 
   retval = old.it_value.tv_sec;
-  if (old.it_value.tv_usec)
+  /* Round to the nearest second, but never report zero seconds when
+     the alarm is still set.  */
+  if (old.it_value.tv_usec >= 500000
+      || (retval == 0 && old.it_value.tv_usec > 0))
     ++retval;
   return retval;
 }