Make touch -t more foolproof so it quits when passed invalid values rather than set time to the epoch. Got bitten by this in a script when Make touch -t more foolproof so it quits when passed invalid values rather than set time to the epoch. And a tiny style fix to make the whole file have a consistent style. Notes: Sat Feb 11 11:04:03 EST 2006 rsc Thanks. Just FYI, the canonical way to test two pointers for equality is s==t. Reference: /n/sources/patch/applied/touch-time-arg-validation Date: Sat Feb 11 13:21:55 CET 2006 Reviewed-by: rsc --- /sys/src/cmd/touch.c Sat Feb 11 13:15:08 2006 +++ /sys/src/cmd/touch.c Sat Feb 11 13:15:05 2006 @@ -14,13 +14,17 @@ void main(int argc, char **argv) { + char *t, *s; int nocreate = 0; int status = 0; now = time(0); ARGBEGIN{ case 't': - now = strtoul(EARGF(usage()), 0, 0); + s = t = EARGF(usage()); + now = strtoul(t, &s, 0); + if(s-t == 0 || *s != '\0') + usage(); break; case 'c': nocreate = 1; @@ -51,7 +55,7 @@ fprint(2, "touch: %s: cannot wstat: %r\n", name); return 1; } - if ((fd = create(name, OREAD|OEXCL, 0666)) < 0) { + if((fd = create(name, OREAD|OEXCL, 0666)) < 0){ fprint(2, "touch: %s: cannot create: %r\n", name); return 1; }