Hi,

This adds strtonum(3)-style error messages to sleep(1).  They're
more informative than the usage statement and they're idiomatic
for numeric input.

Exiting with EINVAL is really unusual.  It went into r1.9.  Unless
I'm missing something I think we can just exit with 1, which is
consistent with what other utilities do.

ok?

--
Scott Cheloha

Index: bin/sleep/sleep.c
===================================================================
RCS file: /cvs/src/bin/sleep/sleep.c,v
retrieving revision 1.25
diff -u -p -r1.25 sleep.c
--- bin/sleep/sleep.c   2 Feb 2018 16:46:37 -0000       1.25
+++ bin/sleep/sleep.c   2 Feb 2018 17:20:58 -0000
@@ -31,7 +31,6 @@
  */
 
 #include <ctype.h>
-#include <errno.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -73,10 +72,10 @@ main(int argc, char *argv[])
        cp = *argv;
        while ((*cp != '\0') && (*cp != '.')) {
                if (!isdigit((unsigned char)*cp))
-                       usage();
+                       errx(1, "seconds is invalid: %s", *argv);
                t = (secs * 10) + (*cp++ - '0');
                if (t / 10 != secs)     /* oflow */
-                       return (EINVAL);
+                       errx(1, "seconds is too large: %s", *argv);
                secs = t;
        }
 
@@ -87,7 +86,7 @@ main(int argc, char *argv[])
                        if (*cp == '\0')
                                break;
                        if (!isdigit((unsigned char)*cp))
-                               usage();
+                               errx(1, "seconds is invalid: %s", *argv);
                        nsecs += (*cp++ - '0') * i;
                }
 
@@ -98,7 +97,7 @@ main(int argc, char *argv[])
                 */
                while (*cp != '\0') {
                        if (!isdigit((unsigned char)*cp++))
-                               usage();
+                               errx(1, "seconds is invalid: %s", *argv);
                }
        }
 

Reply via email to