getopt-posix: detect MacOS bug
authorEric Blake <eblake@redhat.com>
Tue, 13 Apr 2010 20:30:37 +0000 (14:30 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 13 Apr 2010 22:31:47 +0000 (16:31 -0600)
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>
ChangeLog
doc/glibc-functions/getopt_long.texi
doc/glibc-functions/getopt_long_only.texi
doc/posix-functions/getopt.texi
m4/getopt.m4

index 7de81f4..c46bf31 100644 (file)
--- 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.
index 0472514..3cf17f0 100644 (file)
@@ -11,6 +11,10 @@ The function @code{getopt_long} does not support the @samp{+} 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} does not obey the @samp{-} flag in the
 options string when @env{POSIXLY_CORRECT} is set on some platforms:
 Cygwin 1.7.0.
index 13edfb4..edc832b 100644 (file)
@@ -11,6 +11,10 @@ The function @code{getopt_long_only} does not support the @samp{+}
 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.
index 822dbb3..d4d03f0 100644 (file)
@@ -16,6 +16,10 @@ Portability problems fixed by either Gnulib module @code{getopt-posix} or @code{
 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}:
index 8d3d8b6..2cd7499 100644 (file)
@@ -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 @@ main ()
     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 @@ main ()
           [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
           ])