diff options
author | Erik Troan <ewt@redhat.com> | 1999-07-22 01:58:26 +0000 |
---|---|---|
committer | Erik Troan <ewt@redhat.com> | 1999-07-22 01:58:26 +0000 |
commit | 2c7b3a955e8c7eb9ad88bc46ff87ecf7aea670f0 (patch) | |
tree | 27c2fca985f0f3ccffc7abc813c32133333a61ac /src/usleep.c | |
parent | 2ae23baea22c0002c027c2cbd4925b78a829ccc0 (diff) | |
download | initscripts-2c7b3a955e8c7eb9ad88bc46ff87ecf7aea670f0.tar initscripts-2c7b3a955e8c7eb9ad88bc46ff87ecf7aea670f0.tar.gz initscripts-2c7b3a955e8c7eb9ad88bc46ff87ecf7aea670f0.tar.bz2 initscripts-2c7b3a955e8c7eb9ad88bc46ff87ecf7aea670f0.tar.xz initscripts-2c7b3a955e8c7eb9ad88bc46ff87ecf7aea670f0.zip |
popt'd usleep (djb made me)
Diffstat (limited to 'src/usleep.c')
-rw-r--r-- | src/usleep.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/usleep.c b/src/usleep.c index 2d0a5565..12cabed7 100644 --- a/src/usleep.c +++ b/src/usleep.c @@ -11,27 +11,44 @@ #include <string.h> #include <stdio.h> -int main(int argc, char **argv) -{ - - double count; - - if (argc == 1) count=1; - else if (!strcmp(argv[1], "--help")) - { - printf("usleep [number]\n sleep [number] of microseconds\n the default number to sleep is 1 microsecond\n"); - exit(0); - } - else if (!strcmp(argv[1], "-v")) - { - printf("usleep version 1.0 by Donald Barnes <djb@redhat.com>\n usleep --help for more info\n"); - exit(0); - } - else - count = strtod(argv[1], NULL); +int main(int argc, char **argv) { + unsigned long count; + poptContext optCon; + int showVersion = 0; + int rc; + char * countStr; + struct poptOption options[] = { + { "version", 'v', POPT_ARG_NONE, &showVersion, 0, + "Display the version of this program, and exit" }, + POPT_AUTOHELP + { 0, 0, 0, 0, 0 } + }; + + optCon = poptGetContext("usleep", argc, argv, options,0); + /*poptReadDefaultConfig(optCon, 1);*/ + poptSetOtherOptionHelp(optCon, "[microseconds]"); + + if ((rc = poptGetNextOpt(optCon)) < -1) { + fprintf(stderr, "usleep: bad argument %s: %s\n", + poptBadOption(optCon, POPT_BADOPTION_NOALIAS), + poptStrerror(rc)); + return 2; + } + + if (showVersion) { + printf("usleep version 1.1 by Donald Barnes <djb@redhat.com>\n usleep --help for more info\n"); + return 0; + } + + countStr = poptGetArg(optCon); + if (countStr && poptGetArg(optCon)) { + fprintf(stderr, "usleep: exactly one argument (number of microseconds) " + "must be used\n"); + return 2; + } + + count = strtoul(countStr, NULL, 0); usleep(count); - exit(0); - - + return 0; } |