diff options
author | Gianluca Anzolin <gianluca@sottospazio.it> | 2014-11-25 08:56:03 +0100 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2014-12-02 19:03:04 -0500 |
commit | b72cd07f176b876aa51864d93aa8101477b1d732 (patch) | |
tree | 63bbeee711e3a31e7c136451160efbfb4e69a548 /src/misc/getopt_long.c | |
parent | d8dc2b7c0289b12eeef4feff65e3c918111b0f55 (diff) | |
download | musl-b72cd07f176b876aa51864d93aa8101477b1d732.tar.gz musl-b72cd07f176b876aa51864d93aa8101477b1d732.tar.bz2 musl-b72cd07f176b876aa51864d93aa8101477b1d732.tar.xz musl-b72cd07f176b876aa51864d93aa8101477b1d732.zip |
add support for non-option arguments extension to getopt
this is a GNU extension, activated by including '-' as the first
character of the options string, whereby non-option arguments are
processed as if they were arguments to an option character '\1' rather
than ending option processing.
Diffstat (limited to 'src/misc/getopt_long.c')
-rw-r--r-- | src/misc/getopt_long.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 4ef5a5c7..3d318ce5 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -12,9 +12,10 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con __optpos = 0; optind = 1; } - if (optind >= argc || !argv[optind] || argv[optind][0] != '-') return -1; - if ((longonly && argv[optind][1]) || - (argv[optind][1] == '-' && argv[optind][2])) + if (optind >= argc || !argv[optind]) return -1; + if (argv[optind][0] == '-' && + ((longonly && argv[optind][1]) || + (argv[optind][1] == '-' && argv[optind][2]))) { int i; for (i=0; longopts[i].name; i++) { |