From dc620e69a5f031d9bbf327f3f7afaff2e3ade62f Mon Sep 17 00:00:00 2001 From: delphij Date: Tue, 14 Dec 2010 01:16:56 +0000 Subject: IEEE Std 1003.1-2008, Section 1.4, Utility Description Defaults says that when the options section is listed as "None", utility shall recognize "--" as a first argument to be discarded. This implementation is largely based on OpenBSD implementation but we do slightly differently: a) We skip argv[0] as the first step; b) We test whether the next argument is "--" and ignore it. With this change one will get: %printf usage: printf format [arguments ...] %printf -v -v%printf -- -v -v% %printf -- usage: printf format [arguments ...] Which matches the behavior observed on a Debian system but different from the Illumos change. --- usr.bin/printf/printf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'usr.bin/printf') diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 03e0dee..1151855 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) { size_t len; - int ch, chopped, end, rval; + int chopped, end, rval; char *format, *fmt, *start; #ifndef SHELL @@ -111,15 +111,15 @@ main(int argc, char *argv[]) #ifdef SHELL optreset = 1; optind = 1; opterr = 0; /* initialize getopt */ #endif - while ((ch = getopt(argc, argv, "")) != -1) - switch (ch) { - case '?': - default: - usage(); - /* NOTREACHED */ - } - argc -= optind; - argv += optind; + /* Skip argv[0] which is the process name */ + argv++; + argc--; + + /* Need to accept/ignore "--" option. */ + if (argc >= 1 && strcmp(*argv, "--") == 0) { + argc--; + argv++; + } if (argc < 1) { usage(); -- cgit v1.1