On Sat, Dec 01, 2018 at 08:58:31AM +0100, Martijn van Duren wrote:
> > I'm not sure the EINVAL error string adds valuable information. I would
> > prefer if all these used variants of the idiom suggested in the strtonum
> > manual, something like:
> >
> > errx("number of seconds is %s: %s", errstr, optarg);
> > errx("battery percentage is %s: %s", errstr, optarg);
> >
> That might be even better.
I agree, thanks for the input.
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 13:19:55 -0000
@@ -392,9 +392,10 @@ 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)
+ errx(1, "number of seconds is %s: %s", errstr,
+ optarg);
break;
case 's': /* status only */
statonly = 1;
@@ -422,14 +423,14 @@ main(int argc, char *argv[])
autoaction = AUTO_HIBERNATE;
autolimit = strtonum(optarg, 1, 100, &errstr);
if (errstr != NULL)
- errc(1, EINVAL, "%s percentage: %s", errstr,
+ errx(1, "battery percentage is %s: %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,
+ errx(1, "battery percentage is %s: %s", errstr,
optarg);
break;
case '?':