summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/getopt_long.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* This patch fixes one bug and one instance of undesirable behaviour.schwarze2020-05-271-9/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug, present since 4.4BSD, was that a trailing dash in an option group, when the dash is not permitted as an option letter, resulted in the whole option group being returned as an argument, even though the previous option in the group was already parsed as an option: OPTS=abc ./getopt-test -a- -c arg ===>> OPT(a)ARG(-a-)ARG(-c)ARG(arg). Instead, treat the dash as an invalid option and continue parsing options: ===>> OPT(a)ERR(?-)OPT(c)ARG(arg). The undesirable behaviour was that allowing the dash as an option letter only allowed isolated dashes ("-") and trailing dashes in groups ("-a-"), but neither middle dashes in groups ("-a-b"), even though that already partially worked in 4.4BSD, nor leading dashes in groups ("--a"), even though that works on all other BSDs and on glibc. Also, while POSIX does not require that the dash can be used as an option letter at all, arguably, it encourages that letters either be fully supported or not supported at all. It is dubious whether supporting an option letter in some positions but not in others can be considered conforming. This patch makes OpenBSD behaviour identical to FreeBSD and NetBSD, improves compatibility with glibc (except that glibc does not support isolated "-"), improves compatibility with DragonFly (except that DragonFly is buggy when the dash option letter can take an optional argument but that argument is not present), improves compatibility with Illumos and Solaris 11 (except those do not support "-" and mishandle "--a"), and restores 4.4BSD behaviour for "-a-b". In no respect i'm aware of is compatibility with any other systems reduced. For the full rationale, see my mail to tech@ on 30 Mar 2020 14:26:41 +0200. Part of the problem was originally reported by an anonymous coward on tech@ on 12 Mar 2020 03:40:24 +0200, additional analysis was contributed by martijn@, and then the OP sent the final version of the patch i'm now committing on 17 Mar 2020 19:17:56 +0200. No licensing problem here because after the commit, the file does not contain a single word written by the OP. Also, the OP told me in private mail that he intends to publish the patch under the ISC license already contained in the file and that he wishes to be known by the pseudonym "0xef967c36". OK martijn@, and no objection when shown on tech@, but commit delayed to stay clear of the release.
* "eventually" came and went back in 2004.libressl-v3.1.0martijn2020-03-301-3/+1
| | | | OK schwarze@
* I am retiring my old email address; replace it with my OpenBSD one.millert2019-01-251-2/+2
|
* Eliminate the last of the LINTEDn and PRINTFLIKEn comments. In oneguenther2015-10-011-4/+2
| | | | | | | case, by deleting some useless '& of an array' we also eliminate the need for the casts which prompted the original lint warnings ok deraadt@
* Don't wrap initialized variables: binutils appears to be mishandling themguenther2015-09-191-1/+3
| | | | | | on arm and m88k problems with optind observed by jsg@
* Wrap <getopt.h> to make the functions weak and make access to the initializedguenther2015-09-121-1/+6
| | | | variables go direct. (Common variables cannot be aliased.)
* Fix parsing of ambiguous options, the whole loop must be processed.millert2013-06-081-15/+22
| | | | From FreeBSD. OK miod@
* Fix PR 6267: recheck POSIXLY_CORRECT each time getopt_long() starts a newguenther2011-03-051-12/+12
| | | | | | | | argv and don't suppress the handling of leading '-' in optstring when POSIXLY_CORRECT is set. Based on patch from Eric Blake. ok and manpage update from millert@, manpage ok jmc@
* getopt_long.c replaced getopt.c 6+ years ago; we can retireblambert2010-07-221-7/+1
| | | | | | the REPLACE_GETOPT macro, at long last ok millert@
* Add parentheses to avoid warning:chl2007-10-311-2/+2
| | | | | | "suggest parentheses around && within ||" ok millert@
* from wiz@netbsd:jmc2006-10-041-8/+1
| | | | | | Log Message: Switch from 4-clause to 2-clause BSD license. Ok dillo@, board@.
* Back out change in rev 1.15 of to allow whitespace to separate amillert2006-09-221-10/+1
| | | | | | | | | flag from its optional argument if permutation is disabled. The idea was that since "r:" would match "-r foo" then "r::" should match "-r foo" too as long as we know that things have not been reshuffled. Unfortunately, this causes incompatibilities with GNU getopt_long when the POSIXLY_CORRECT environment variable is set. OK deraadt@
* dont' -> don't in comments;jmc2005-10-251-2/+2
| | | | from ray lai;
* zap remaining rcsid.espie2005-08-081-5/+1
| | | | | | Kill old files that are no longer compiled. okay theo
* ansi + de-registerpat2005-03-301-14/+6
| | | | ok otto deraadt
* An optional argument cannot start with '-', even if permutation ismillert2004-06-031-4/+5
| | | | disabled. Magne Oestlyngen.
* Traditionally, getopt(3) has treated "--foo" the same as "--". However,millert2004-02-041-10/+9
| | | | | | | | this can cause confusion when a user tries to use a long option with a program that only supports short options. Furthermore, it appears to be in violation of POSIX, which states that "--" shall indicate the end of argument processing, not any string that begins with "--". OK otto@ and closes PR 3666.
* If permutation is disabled (as it is via getopt(3) or when POSIXLY_CORRECTmillert2003-09-221-2/+9
| | | | | | is set), we can accept an optional arg separated by whitespace. Previously, the optional arg needed to be adjacent to the option character. deraadt@ OK
* Sync with share/misc/license.template and add missing DARPA creditmillert2003-06-171-9/+13
| | | | where applicable.
* Use an ISC-tyle license for all my code; it is simpler and more permissive.millert2003-06-031-23/+12
|
* Use the getopt() in getopt_long.c which supports some GNU extensions.millert2003-06-021-2/+4
| | | | getopt.c is no longer compiled and will eventually be removed.
* When doing permutation, only treat "-" as an option if it was specifiedmillert2002-12-101-4/+5
| | | | in optstring. Problem noticed by Theo.
* SUS (and apparently 1003.1-2001) say to check optstring for NULLmillert2002-12-081-3/+5
|
* If we are passed "-" in argv and the user didn't specify '-' in optstring,millert2002-12-081-6/+10
| | | | return -1 like POSIX requires.
* BSD getopt() supports '-' in the optstring so we should too.millert2002-12-081-8/+15
| | | | This is used by a few programs such as man and su.
* Fix pasto in last commit.millert2002-12-071-3/+3
|
* For getopt_long_only() we *do* want to match single-character optionsmillert2002-12-071-41/+36
| | | | | as shortcuts for long ones, but only if this would not conflict with a short option in optstring. Now binutils gas works.
* Fix two compatibility issues with our getopt_long_only() vs. the GNU version:millert2002-12-061-28/+61
| | | | | | | | | | | | | | o Check for long options even when not at the beginning of an option. For instance, if -a is a short option w/o an arg and -static is a boolean long option then -astatic is valid for getopt_long_only(). o If a potential long argument does not match longopts and the first character is not a short option, print a warning and skip the rest of the argument. Also clean up some trailing whitespace and change return value of parse_long_options() from -2 to -1 when unmatched and in long_only mode. With these fixes the binutils ld seems happy with our getopt_long_only()
* Correctly handle -Wlong_arg (no space between -W and long_arg) when "W;"millert2002-12-051-6/+8
| | | | is in optstring.
* Reorganize this so that getopt_only_only() works correctly.millert2002-12-051-221/+208
| | | | | | | | In order for getopt_only_only() to work we need to check for long options before short ones. I have merged getopt_internal and getopt_long_internal into a single function with the actual long args parsing broken out into a separate function. This also simplifies the flow of control.
* Whoops, add missing #ifdef REPLACE_GETOPTmillert2002-12-031-2/+4
|
* GNU-like getopt_long() from NetBSD with changes by me to supportmillert2002-12-031-0/+510
getopt_long_only(). At some point this should replace the BSD getopt(3) but we are not there yet. While I am here add protection from the multiple getopt() definitions due to conflicting standards.