summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-06-11 23:38:44 -0400
committerRich Felker <dalias@aerifal.cx>2014-06-11 23:38:44 -0400
commit66fcde4ae4a52ae3edb1cf237ce2c22d08d7a062 (patch)
tree26f7f4b223b219c19aeb51a586bee9617bb02536 /src
parentd79b27785fb2476017225b13d24e4b8d408f61c6 (diff)
downloadmusl-66fcde4ae4a52ae3edb1cf237ce2c22d08d7a062.tar.gz
support optional-argument extension to getopt via double-colon
this extension is not incompatible with the standard behavior of the function, not expensive, and avoids requiring a replacement getopt with full GNU extensions for a few important apps including busybox's sed with the -i option.
Diffstat (limited to 'src')
-rw-r--r--src/misc/getopt.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/misc/getopt.c b/src/misc/getopt.c
index f1a1639c..8a2e4d50 100644
--- a/src/misc/getopt.c
+++ b/src/misc/getopt.c
@@ -65,8 +65,11 @@ int getopt(int argc, char * const argv[], const char *optstring)
}
return '?';
}
- optarg = argv[optind++] + optpos;
- optpos = 0;
+ if (optstring[i+2] == ':') optarg = 0;
+ if (optstring[i+2] != ':' || optpos) {
+ optarg = argv[optind++] + optpos;
+ optpos = 0;
+ }
}
return c;
}