]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
scriptreplay: avoid re-implementing strtod_or_err()
authorSami Kerola <kerolasa@iki.fi>
Sun, 1 May 2016 22:56:05 +0000 (23:56 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 5 May 2016 09:46:54 +0000 (11:46 +0200)
And use isnan() to detect NaN.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
term-utils/Makemodule.am
term-utils/scriptreplay.c

index ea1affcdcb95283363a5302c1341584d3ef5d4cf..8ddb0687b4b32b4e5e28151733d501e0e8ded8cb 100644 (file)
@@ -21,6 +21,7 @@ if BUILD_SCRIPTREPLAY
 usrbin_exec_PROGRAMS += scriptreplay
 dist_man_MANS += term-utils/scriptreplay.1
 scriptreplay_SOURCES = term-utils/scriptreplay.c
+scriptreplay_LDADD = $(LDADD) libcommon.la
 endif # BUILD_SCRIPTREPLAY
 
 
index 51985cda8fb98173091b10e8d83df4cea4558aa5..146133518e2974802aa80d6a87c2fd18848fd2b9 100644 (file)
@@ -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;
 }