diff options
author | njl <njl@FreeBSD.org> | 2002-11-14 01:14:35 +0000 |
---|---|---|
committer | njl <njl@FreeBSD.org> | 2002-11-14 01:14:35 +0000 |
commit | 017be360f49ae83684bbcfc2212622e4345a13e6 (patch) | |
tree | 8ea47fd0f2dcabcd07431cf342cdb6bf7085a905 | |
parent | a274e06113a656aa1742ad77624a7a8ca4dee0ce (diff) | |
download | FreeBSD-src-017be360f49ae83684bbcfc2212622e4345a13e6.zip FreeBSD-src-017be360f49ae83684bbcfc2212622e4345a13e6.tar.gz |
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
-rw-r--r-- | bin/sleep/sleep.c | 24 |
1 files changed, 9 insertions, 15 deletions
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 <ctype.h> #include <limits.h> -#include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> +#include <string.h> 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); } |