fix getopt[_long] clobbering of optopt on success
commit786fda875a901dc1807289c940338487854cd3ba
authorRich Felker <dalias@aerifal.cx>
Thu, 5 Jan 2017 00:02:02 +0000 (4 19:02 -0500)
committerRich Felker <dalias@aerifal.cx>
Thu, 5 Jan 2017 00:43:59 +0000 (4 19:43 -0500)
tree88c2340198a714d912e61fd26bae9580d072f1f3
parent150747b41e1ecefe82aa45d68c84b9e957b03e29
fix getopt[_long] clobbering of optopt on success

getopt is only specified to modify optopt on error, and some software
apparently infers an error from optopt!=0.

getopt_long is changed analogously. the resulting behavior differs
slightly from the behavior of the GNU implementation of getopt_long,
which keeps an internal shadow copy of optopt and copies it to the
public one on return, but since the GNU implementation also exhibits
this shadow-copy behavior for plain getopt where is is non-conforming,
I think this can reasonably be considered a bug rather than an
intentional behavior that merits mimicing.
src/misc/getopt.c
src/misc/getopt_long.c