提交 66fcde4a 编写于 作者: R Rich Felker

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.
上级 d79b2778
...@@ -65,9 +65,12 @@ int getopt(int argc, char * const argv[], const char *optstring) ...@@ -65,9 +65,12 @@ int getopt(int argc, char * const argv[], const char *optstring)
} }
return '?'; return '?';
} }
if (optstring[i+2] == ':') optarg = 0;
if (optstring[i+2] != ':' || optpos) {
optarg = argv[optind++] + optpos; optarg = argv[optind++] + optpos;
optpos = 0; optpos = 0;
} }
}
return c; return c;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册