X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fgetopt.m4;h=5b211e5678be6ac4f24b2dfa2ea00ca5c7c1e568;hb=ef7ac3461d310630096bd41909677a597c810242;hp=8b1bb8fbf21599bf612e0b26261fc29d87e3fe91;hpb=a8ec28b6975fc065b84c511b8108dc3658d2ccd4;p=gnulib.git diff --git a/m4/getopt.m4 b/m4/getopt.m4 index 8b1bb8fbf..5b211e567 100644 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -1,5 +1,5 @@ -# getopt.m4 serial 24 -dnl Copyright (C) 2002-2006, 2008-2009 Free Software Foundation, Inc. +# getopt.m4 serial 28 +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, dnl with or without modifications, as long as this notice is preserved. @@ -79,8 +79,13 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], dnl Existence of the variable, in and of itself, is not a reason to replace dnl getopt, but knowledge of the variable is needed to determine how to dnl reset and whether a reset reparses the environment. - if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then - AC_CHECK_DECLS([optreset], [], [], + dnl Solaris supports neither optreset nor optind=0, but keeps no state that + dnl needs a reset beyond setting optind=1; detect Solaris by getopt_clip. + if test -z "$gl_replace_getopt"; then + AC_CHECK_DECLS([optreset], [], + [AC_CHECK_DECLS([getopt_clip], [], [], + [[#include ]]) + ], [[#include ]]) fi @@ -89,6 +94,10 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], dnl is left over from earlier calls, and neither setting optind = 0 nor dnl setting optreset = 1 get rid of this internal state. dnl POSIX is silent on optind vs. optreset, so we allow either behavior. + dnl POSIX 2008 does not specify leading '+' behavior, but see + dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on + dnl the next version of POSIX. For now, we only guarantee leading '+' + dnl behavior with getopt-gnu. if test -z "$gl_replace_getopt"; then AC_CACHE_CHECK([whether getopt is POSIX compatible], [gl_cv_func_getopt_posix], @@ -99,7 +108,7 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], #include #include -#if !HAVE_DECL_OPTRESET +#if !HAVE_DECL_OPTRESET && !HAVE_DECL_GETOPT_CLIP # define OPTIND_MIN 0 #else # define OPTIND_MIN 1 @@ -167,6 +176,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; } @@ -174,6 +197,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 ]) @@ -234,6 +258,15 @@ main () if (getopt (3, argv, "-p") != 'p') return 7; } + /* This code fails on glibc 2.11. */ + { + char *argv[] = { "program", "-b", "-a", NULL }; + optind = opterr = 0; + if (getopt (3, argv, "+:a:b") != 'b') + return 8; + if (getopt (3, argv, "+:a:b") != ':') + return 9; + } return 0; ]])], [gl_cv_func_getopt_gnu=yes],