summaryrefslogtreecommitdiffstats
path: root/term-utils/scriptreplay.c
diff options
context:
space:
mode:
authorSami Kerola2016-05-02 00:56:05 +0200
committerKarel Zak2016-05-05 11:46:54 +0200
commitf0b3b904c7972374e8b9a280164508e356e9b5be (patch)
tree308b3a4e7091bd87720479abb95aa9cb720ce875 /term-utils/scriptreplay.c
parentscriptreplay: improve error message (diff)
downloadkernel-qcow2-util-linux-f0b3b904c7972374e8b9a280164508e356e9b5be.tar.gz
kernel-qcow2-util-linux-f0b3b904c7972374e8b9a280164508e356e9b5be.tar.xz
kernel-qcow2-util-linux-f0b3b904c7972374e8b9a280164508e356e9b5be.zip
scriptreplay: avoid re-implementing strtod_or_err()
And use isnan() to detect NaN. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/scriptreplay.c')
-rw-r--r--term-utils/scriptreplay.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c
index 51985cda8..146133518 100644
--- a/term-utils/scriptreplay.c
+++ b/term-utils/scriptreplay.c
@@ -30,6 +30,7 @@
#include "closestream.h"
#include "nls.h"
+#include "strutils.h"
#include "c.h"
#define SCRIPT_MIN_DELAY 0.0001 /* from original sripreplay.pl */
@@ -60,21 +61,11 @@ usage(FILE *out)
static double
getnum(const char *s)
{
- double d;
- char *end;
+ const double d = strtod_or_err(s, _("failed to parse number"));
- errno = 0;
- d = strtod(s, &end);
-
- if (end && *end != '\0')
- errx(EXIT_FAILURE, _("expected a number, but got '%s'"), s);
-
- if ((d == HUGE_VAL || d == -HUGE_VAL) && ERANGE == errno)
- err(EXIT_FAILURE, _("divisor '%s'"), s);
-
- if (!(d==d)) { /* did they specify "nan"? */
+ if (isnan(d)) {
errno = EINVAL;
- err(EXIT_FAILURE, _("divisor '%s'"), s);
+ err(EXIT_FAILURE, "%s: %s", _("failed to parse number"), s);
}
return d;
}