getopt-gnu: flush out another BSD bug
authorEric Blake <ebb9@byu.net>
Sat, 28 Nov 2009 00:47:21 +0000 (17:47 -0700)
committerEric Blake <ebb9@byu.net>
Sat, 28 Nov 2009 03:29:00 +0000 (20:29 -0700)
commitc0c5acfbe255f5542bc1c81c7aec223d95e504a6
tree6468907399b6bf7841b10092d149a829a9bc3185
parent6184bd1482b08fb6e3076931b73cbf09639509bc
getopt-gnu: flush out another BSD bug

POSIX requires 'echo foo > bar; m4 -Dfoo=1 bar -Dfoo=2 bar' to
output '1' then '2'.  To achieve this, m4 relies on the GNU
getopt{,_long} extension of a leading '-'.  However, BSD getopt
fails to honor this extension when POSIXLY_CORRECT.

Also, BSD getopt fails to reparse POSIXLY_CORRECT from the
environment even when a reset is requested (whether by
optreset=1 or by optind=0).

* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Test for the bug.
* tests/test-getopt.c (main): Check POSIXLY_CORRECT first, to
flush out BSD bug.
* tests/test-getopt.h (test_getopt): End lists with NULL.
* tests/test-getopt_long.h (test_getopt_long): Likewise.
(test_getopt_long_posix): Enhance test.
* modules/getopt-posix-tests (Depends-on): Add stdbool.
* doc/glibc-functions/getopt_long.texi (getopt_long): Mention
getopt-gnu.
* doc/glibc-functions/getopt_long_only.texi (getopt_long_only):
Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
doc/glibc-functions/getopt_long.texi
doc/glibc-functions/getopt_long_only.texi
doc/posix-functions/getopt.texi
m4/getopt.m4
modules/getopt-posix-tests
tests/test-getopt.c
tests/test-getopt.h
tests/test-getopt_long.h