Mercurial > hg > octave-lojdl > gnulib-hg
changeset 13226:9ab255e8b6a9
getopt-posix: detect MacOS bug
On MacOS 10.5 (Darwin 9.8.0), optind is incremented by 2 instead
of 1 in the case of a missing requirement on condensed options.
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Reject MacOS botch of
optind when missing a required argument.
* doc/posix-functions/getopt.texi (getopt): Document the bug.
* doc/glibc-functions/getopt_long.texi (getopt_long): Likewise.
* doc/glibc-functions/getopt_long_only.texi (getopt_long_only):
Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Tue, 13 Apr 2010 14:30:37 -0600 |
parents | fad1d987bb38 |
children | a86548279d8e |
files | ChangeLog doc/glibc-functions/getopt_long.texi doc/glibc-functions/getopt_long_only.texi doc/posix-functions/getopt.texi m4/getopt.m4 |
diffstat | 5 files changed, 36 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-04-13 Eric Blake <eblake@redhat.com> + getopt-posix: detect MacOS bug + * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Reject MacOS botch of + optind when missing a required argument. + * doc/posix-functions/getopt.texi (getopt): Document the bug. + * doc/glibc-functions/getopt_long.texi (getopt_long): Likewise. + * doc/glibc-functions/getopt_long_only.texi (getopt_long_only): + Likewise. + getopt-posix: avoid spurious failure on Solaris * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Check for getopt_clip as an indicator that setting optind=1 is sufficient for reset.
--- a/doc/glibc-functions/getopt_long.texi +++ b/doc/glibc-functions/getopt_long.texi @@ -11,6 +11,10 @@ the options string on some platforms: MacOS X 10.5, AIX 5.2, OSF/1 5.1, Solaris 10. @item +The value of @code{optind} after a missing required argument is wrong +on some platforms: +MacOS 10.5. +@item The function @code{getopt_long} does not obey the @samp{-} flag in the options string when @env{POSIXLY_CORRECT} is set on some platforms: Cygwin 1.7.0.
--- a/doc/glibc-functions/getopt_long_only.texi +++ b/doc/glibc-functions/getopt_long_only.texi @@ -11,6 +11,10 @@ flag in the options string on some platforms: MacOS X 10.5, AIX 5.2, OSF/1 5.1, Solaris 10. @item +The value of @code{optind} after a missing required argument is wrong +on some platforms: +MacOS 10.5. +@item The function @code{getopt_long_only} does not obey the @samp{-} flag in the options string when @env{POSIXLY_CORRECT} is set on some platforms: Cygwin 1.7.0.
--- a/doc/posix-functions/getopt.texi +++ b/doc/posix-functions/getopt.texi @@ -16,6 +16,10 @@ The @code{getopt} function keeps some internal state that cannot be explicitly reset on some platforms: mingw. +@item +The value of @code{optind} after a missing required argument is wrong +on some platforms: +MacOS 10.5. @end itemize Portability problems fixed by Gnulib module @code{getopt-gnu}:
--- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -1,4 +1,4 @@ -# getopt.m4 serial 26 +# getopt.m4 serial 27 dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -172,6 +172,20 @@ if (!(optind == 1)) return 12; } + /* Detect MacOS 10.5 bug. */ + { + char *argv[3] = { "program", "-ab", NULL }; + optind = OPTIND_MIN; + opterr = 0; + if (getopt (2, argv, "ab:") != 'a') + return 13; + if (getopt (2, argv, "ab:") != '?') + return 14; + if (optopt != 'b') + return 15; + if (optind != 2) + return 16; + } return 0; } @@ -179,6 +193,7 @@ [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no], [case "$host_os" in mingw*) gl_cv_func_getopt_posix="guessing no";; + darwin*) gl_cv_func_getopt_posix="guessing no";; *) gl_cv_func_getopt_posix="guessing yes";; esac ])