From: Rich Felker Date: Thu, 12 Jun 2014 03:38:44 +0000 (-0400) Subject: support optional-argument extension to getopt via double-colon X-Git-Tag: v1.1.3~30 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=66fcde4ae4a52ae3edb1cf237ce2c22d08d7a062;p=oweals%2Fmusl.git 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. --- 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; }