From 017be360f49ae83684bbcfc2212622e4345a13e6 Mon Sep 17 00:00:00 2001 From: njl Date: Thu, 14 Nov 2002 01:14:35 +0000 Subject: Minimal take on previous commit -- remove getopt and printf. Static size is reduced by 40k, dynamic by a few bytes. Functional changes: * "sleep -- arg" now returns usage() instead of ignoring the -- * "sleep -1" now returns immediately instead of returning usage() Reviewed by: jmallett --- bin/sleep/sleep.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'bin') diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c index 7b1fb2a..0086ee0 100644 --- a/bin/sleep/sleep.c +++ b/bin/sleep/sleep.c @@ -47,10 +47,10 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include +#include void usage(void); @@ -59,25 +59,15 @@ main(int argc, char *argv[]) { struct timespec time_to_sleep; long l; - int ch, neg; + int neg; char *p; - while ((ch = getopt(argc, argv, "")) != -1) - switch(ch) { - case '?': - default: - usage(); - /* NOTREACHED */ - } - argc -= optind; - argv += optind; - - if (argc != 1) { + if (argc != 2) { usage(); /* NOTREACHED */ } - p = argv[0]; + p = argv[1]; /* Skip over leading whitespaces. */ while (isspace((unsigned char)*p)) @@ -88,6 +78,9 @@ main(int argc, char *argv[]) if (*p == '-') { neg = 1; ++p; + if (!isdigit((unsigned char)*p) && *p != '.') + usage(); + /* NOTREACHED */ } else if (*p == '+') ++p; @@ -128,7 +121,8 @@ main(int argc, char *argv[]) void usage(void) { + const char *msg = "usage: sleep seconds\n"; - (void)fprintf(stderr, "usage: sleep seconds\n"); + write(STDERR_FILENO, msg, strlen(msg)); exit(1); } -- cgit v1.1