diff options
author | Eric Blake <ebb9@byu.net> | 2009-01-13 21:59:35 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-01-14 14:32:13 -0700 |
commit | 7b1967351c80c56abc5b8c6c4a66ffba80050c5c (patch) | |
tree | 50837c792ec3c309bf36f03db3b160b3750832b6 /src/test.c | |
parent | d01338eb3d30e5634f1b4d4179c229f54eea0b44 (diff) | |
download | coreutils-7b1967351c80c56abc5b8c6c4a66ffba80050c5c.tar.xz |
test, echo, printf: don't accept option abbreviation
* src/test.c (main): Directly parse accepted options, thus
avoiding abbreviations.
* src/echo.c (main): Likewise.
* src/printf.c (main): Likewise.
Diffstat (limited to 'src/test.c')
-rw-r--r-- | src/test.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/test.c b/src/test.c index 14d20fd27..c56ab9e3c 100644 --- a/src/test.c +++ b/src/test.c @@ -2,7 +2,7 @@ /* Modified to run with the GNU shell by bfox. */ -/* Copyright (C) 1987-2005, 2007-2008 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005, 2007-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -819,16 +819,25 @@ main (int margc, char **margv) if (LBRACKET) { /* Recognize --help or --version, but only when invoked in the - "[" form, and when the last argument is not "]". POSIX - allows "[ --help" and "[ --version" to have the usual GNU - behavior, but it requires "test --help" and "test --version" - to exit silently with status 0. */ - if (margc < 2 || !STREQ (margv[margc - 1], "]")) + "[" form, when the last argument is not "]". Use direct + parsing, rather than parse_long_options, to avoid accepting + abbreviations. POSIX allows "[ --help" and "[ --version" to + have the usual GNU behavior, but it requires "test --help" + and "test --version" to exit silently with status 0. */ + if (margc == 2) { - parse_long_options (margc, margv, PROGRAM_NAME, PACKAGE_NAME, Version, - usage, AUTHORS, (char const *) NULL); - test_syntax_error (_("missing `]'"), NULL); + if (STREQ (margv[1], "--help")) + usage (EXIT_SUCCESS); + + if (STREQ (margv[1], "--version")) + { + version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS, + (char *) NULL); + test_exit (EXIT_SUCCESS); + } } + if (margc < 2 || !STREQ (margv[margc - 1], "]")) + test_syntax_error (_("missing `]'"), NULL); --margc; } |