summaryrefslogtreecommitdiff
path: root/src/sleep.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-11-28 19:59:18 +0000
committerJim Meyering <jim@meyering.net>1999-11-28 19:59:18 +0000
commit062906c83a683ce8ff13b4f44d4fd69e9eb54673 (patch)
tree93b088e5f841fa7519cd8558e88c833eb6f37500 /src/sleep.c
parent2c3fa56cefe8213d6a2827363a3cb4292b654515 (diff)
downloadcoreutils-062906c83a683ce8ff13b4f44d4fd69e9eb54673.tar.xz
Don't include math.h or float.h.
Don't use DBL_MAX. Use TIME_T_MAX instead.
Diffstat (limited to 'src/sleep.c')
-rw-r--r--src/sleep.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/sleep.c b/src/sleep.c
index ee57cb826..2122f3f1e 100644
--- a/src/sleep.c
+++ b/src/sleep.c
@@ -17,17 +17,11 @@
#include <config.h>
#include <stdio.h>
+#include <assert.h>
#include <sys/types.h>
#include <time.h>
#include <getopt.h>
-#include <math.h>
-#if HAVE_FLOAT_H
-# include <float.h>
-#else
-# define DBL_MAX 1.7976931348623159e+308
-#endif
-
#ifndef TIME_T_MAX
# define TIME_T_MAX TYPE_MAXIMUM (time_t)
#endif
@@ -81,6 +75,8 @@ apply_suffix (double *s, char suffix_char)
{
unsigned int multiplier;
+ assert (*s <= TIME_T_MAX);
+
switch (suffix_char)
{
case 0:
@@ -100,7 +96,7 @@ apply_suffix (double *s, char suffix_char)
multiplier = 0;
}
- if (multiplier == 0 || *s > DBL_MAX / multiplier)
+ if (multiplier == 0)
return 1;
*s *= multiplier;
@@ -151,9 +147,11 @@ main (int argc, char **argv)
if (xstrtod (argv[i], &p, &s)
/* No negative intervals. */
|| s < 0
+ /* S must fit in a time_t. */
+ || s > TIME_T_MAX
/* No extra chars after the number and an optional s,m,h,d char. */
|| (*p && *(p+1))
- /* Update S based on suffix char. */
+ /* Check any suffix char and update S based on the suffix. */
|| apply_suffix (&s, *p)
/* Make sure the sum fits in a time_t. */
|| (seconds += s) > TIME_T_MAX