Base 10 suffices, negative numbers should be invalid (not converted) and
zero not treated specially:

        # apmd -dt -1
        apmd: kevent loop: Invalid argument
        # apmd -dt 0
        usage: apmd [-AadHLs] [-f devname] [-S sockname] [-t seconds] [-Z 
percent] [-z percent]
        # apmd -dt 1
        ^C

        # ./obj/apmd -dt -1
        apmd: too small seconds: -1
        # ./obj/apmd -dt 0
        apmd: too small seconds: 0
        # ./obj/apmd -dt 1
        ^C

errstr is precise enough, so drop the "Invalid argument" by using just
err() while here.

Feedback? OK?

Index: apmd.c
===================================================================
RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.82
diff -u -p -r1.82 apmd.c
--- apmd.c      30 Nov 2018 18:05:31 -0000      1.82
+++ apmd.c      1 Dec 2018 00:33:24 -0000
@@ -392,9 +392,9 @@ main(int argc, char *argv[])
                        sockname = optarg;
                        break;
                case 't':
-                       ts.tv_sec = strtoul(optarg, NULL, 0);
-                       if (ts.tv_sec == 0)
-                               usage();
+                       ts.tv_sec = strtonum(optarg, 1, LLONG_MAX, &errstr);
+                       if (errstr != NULL)
+                               err(1, "%s seconds: %s", errstr, optarg);
                        break;
                case 's':       /* status only */
                        statonly = 1;
@@ -422,15 +422,13 @@ main(int argc, char *argv[])
                        autoaction = AUTO_HIBERNATE;
                        autolimit = strtonum(optarg, 1, 100, &errstr);
                        if (errstr != NULL)
-                               errc(1, EINVAL, "%s percentage: %s", errstr,
-                                   optarg);
+                               err(1, "%s percentage: %s", errstr, optarg);
                        break;
                case 'z':
                        autoaction = AUTO_SUSPEND;
                        autolimit = strtonum(optarg, 1, 100, &errstr);
                        if (errstr != NULL)
-                               errc(1, EINVAL, "%s percentage: %s", errstr,
-                                   optarg);
+                               err(1, "%s percentage: %s", errstr, optarg);
                        break;
                case '?':
                default:

Reply via email to