about summary refs log tree commit diff
path: root/src/misc/getopt_long.c
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-29 20:36:42 -0600
committerRich Felker <dalias@aerifal.cx>2018-01-31 22:04:50 -0500
commit6f03b61b46d238d480f5b7730ba906e172066e59 (patch)
tree0f4c92a845b87e0c465eb8521b33074fd4de0210 /src/misc/getopt_long.c
parentf1abc29bd09dde14edd942f5868446aaba77f73f (diff)
downloadmusl-6f03b61b46d238d480f5b7730ba906e172066e59.tar.gz
musl-6f03b61b46d238d480f5b7730ba906e172066e59.tar.xz
musl-6f03b61b46d238d480f5b7730ba906e172066e59.zip
getopt_long: accept prefix match of long options containing equals signs
Consider the first equals sign found in the option to be the delimiter
between it and its argument, even if it matches an equals sign in the
option name. This avoids consuming the equals sign, which would prevent
finding the argument. Instead, it forces a partial match of the part of
the option name before the equals sign.

Maintainer's note: GNU getopt_long does not explicitly document this
behavior, but it can be seen as a consequence of how partial matches
are specified, and at least GNU (bfd) ld is known to make use of it.
Diffstat (limited to 'src/misc/getopt_long.c')
-rw-r--r--src/misc/getopt_long.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index 0d1501d4..008b747c 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -63,7 +63,8 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
 			const char *name = longopts[i].name;
 			opt = argv[optind]+1;
 			if (*opt == '-') opt++;
-			for (; *name && *name == *opt; name++, opt++);
+			while (*opt && *opt != '=' && *opt == *name)
+				name++, opt++;
 			if (*opt && *opt != '=') continue;
 			arg = opt;
 			match = i;