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.
 
 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.
 
 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.
 
 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}:
 
-# 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,
     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;
 }
           [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
           ])