summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2006-05-31 08:10:34 +0000
committermaxim <maxim@FreeBSD.org>2006-05-31 08:10:34 +0000
commitcc936f1acc6c1d00f67fa2e74ae0f78fcf2674e0 (patch)
treee7e2aba5b48808a65bde0667096b312a03ac1892 /tools
parent3a3622dbf743fe9e91c425e56032a791596bcd48 (diff)
downloadFreeBSD-src-cc936f1acc6c1d00f67fa2e74ae0f78fcf2674e0.zip
FreeBSD-src-cc936f1acc6c1d00f67fa2e74ae0f78fcf2674e0.tar.gz
o Let getopt(3) report errors in command line arguments.
o If something is wrong with options, then output short usage help message. o Output errstr returned from strtonum(3). PR: bin/98141 Submitted by: Andrey Simonenko
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/sockets/unix_cmsg/unix_cmsg.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/tools/regression/sockets/unix_cmsg/unix_cmsg.c b/tools/regression/sockets/unix_cmsg/unix_cmsg.c
index 4d7cda1..6a39ac3 100644
--- a/tools/regression/sockets/unix_cmsg/unix_cmsg.c
+++ b/tools/regression/sockets/unix_cmsg/unix_cmsg.c
@@ -162,12 +162,15 @@ extern char *__progname; /* The name of program. */
* Output the help message (-h switch).
*/
static void
-usage(void)
+usage(int quick)
{
const struct test_func *test_func;
- fprintf(stderr, "Usage: %s [-dhz] [-t <socktype>] [testno]\n\n", __progname);
- fprintf(stderr, " Options are:\n\
+ fprintf(stderr, "Usage: %s [-dhz] [-t <socktype>] [testno]\n",
+ __progname);
+ if (quick)
+ return;
+ fprintf(stderr, "\n Options are:\n\
-d\t\t\tOutput debugging information\n\
-h\t\t\tOutput this help message and exit\n\
-t <socktype>\t\tRun test only for the given socket type:\n\
@@ -314,15 +317,14 @@ main(int argc, char *argv[])
int opt, dgramflag, streamflag;
u_int testno1, testno2;
- opterr = 0;
dgramflag = streamflag = 0;
- while ((opt = getopt(argc, argv, ":dht:z")) != -1)
+ while ((opt = getopt(argc, argv, "dht:z")) != -1)
switch (opt) {
case 'd':
debug = 1;
break;
case 'h':
- usage();
+ usage(0);
return (EX_OK);
case 't':
if (strcmp(optarg, "stream") == 0)
@@ -335,14 +337,10 @@ main(int argc, char *argv[])
case 'z':
no_control_data = 1;
break;
- case ':':
- errx(EX_USAGE, "option -%c requires an argument", optopt);
- /* NOTREACHED */
case '?':
- errx(EX_USAGE, "invalid switch -%c", optopt);
- /* NOTREACHED */
default:
- errx(EX_SOFTWARE, "unexpected option -%c", optopt);
+ usage(1);
+ return (EX_USAGE);
}
if (optind < argc) {
@@ -350,7 +348,7 @@ main(int argc, char *argv[])
errx(EX_USAGE, "too many arguments");
testno1 = strtonum(argv[optind], 0, UINT_MAX, &errstr);
if (errstr != NULL)
- errx(EX_USAGE, "wrong test number");
+ errx(EX_USAGE, "wrong test number: %s", errstr);
} else
testno1 = 0;
OpenPOWER on IntegriCloud