aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile4
-rw-r--r--src/usleep.111
-rw-r--r--src/usleep.c59
3 files changed, 50 insertions, 24 deletions
diff --git a/src/Makefile b/src/Makefile
index ad7d36bc..1780d65c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,6 +2,7 @@ CFLAGS+=-Wall -D_GNU_SOURCE -g
PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd loglevel
INITLOG_OBJS=initlog.o process.o
+USLEEP_OBJS=usleep.o
all: $(PROGS)
@@ -36,3 +37,6 @@ ipcalc: ipcalc.o
initlog: $(INITLOG_OBJS)
$(CC) $(LDFLAGS) -o $@ $(INITLOG_OBJS) -lpopt
+
+usleep: $(USLEEP_OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(USLEEP_OBJS) -lpopt
diff --git a/src/usleep.1 b/src/usleep.1
index f1e19025..2d7520f7 100644
--- a/src/usleep.1
+++ b/src/usleep.1
@@ -1,4 +1,4 @@
-.TH USLEEP 1 "Red Hat Software" "RHS" \" -*- nroff -*-
+.TH USLEEP 1 "Red Hat, Inc" \" -*- nroff -*-
.SH NAME
usleep \- sleep some number of microseconds
.SH SYNOPSIS
@@ -8,13 +8,18 @@ usleep \- sleep some number of microseconds
.B usleep
sleeps some number of microseconds. The default is 1.
.SH OPTIONS
-\fI--help\fP
+\fI--usage\fP
+Show short usage message.
+.TP
+\fI--help, -?\fP
Print help information.
.TP
-\fI-v\fP
+\fI-v, --version\fP
Print version information.
.SH BUGS
Probably not accurate on many machines down to the microsecond. Count
on precision only to -4 or maybe -5.
.SH AUTHOR
Donald Barnes <djb@redhat.com>
+.br
+Erik Troan <ewt@redhat.com>
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;
}