bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/5] getopt-posix: detect MacOS bug


From: Eric Blake
Subject: [PATCH 3/5] getopt-posix: detect MacOS bug
Date: Tue, 13 Apr 2010 17:17:18 -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 <address@hidden>
---
 ChangeLog                                 |    8 ++++++++
 doc/glibc-functions/getopt_long.texi      |    4 ++++
 doc/glibc-functions/getopt_long_only.texi |    4 ++++
 doc/posix-functions/getopt.texi           |    4 ++++
 m4/getopt.m4                              |   17 ++++++++++++++++-
 5 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7de81f4..c46bf31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2010-04-13  Eric Blake  <address@hidden>

+       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.
diff --git a/doc/glibc-functions/getopt_long.texi 
b/doc/glibc-functions/getopt_long.texi
index 0472514..3cf17f0 100644
--- a/doc/glibc-functions/getopt_long.texi
+++ b/doc/glibc-functions/getopt_long.texi
@@ -11,6 +11,10 @@ getopt_long
 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.
address@hidden
 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.
diff --git a/doc/glibc-functions/getopt_long_only.texi 
b/doc/glibc-functions/getopt_long_only.texi
index 13edfb4..edc832b 100644
--- a/doc/glibc-functions/getopt_long_only.texi
+++ b/doc/glibc-functions/getopt_long_only.texi
@@ -11,6 +11,10 @@ getopt_long_only
 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.
address@hidden
 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.
diff --git a/doc/posix-functions/getopt.texi b/doc/posix-functions/getopt.texi
index 822dbb3..d4d03f0 100644
--- a/doc/posix-functions/getopt.texi
+++ b/doc/posix-functions/getopt.texi
@@ -16,6 +16,10 @@ getopt
 The @code{getopt} function keeps some internal state that cannot be explicitly
 reset on some platforms:
 mingw.
address@hidden
+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}:
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index 8d3d8b6..2cd7499 100644
--- 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 @@ 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
           ])
-- 
1.6.6.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]