summaryrefslogtreecommitdiffstats
path: root/gl/m4/getopt.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/getopt.m4')
-rw-r--r--gl/m4/getopt.m441
1 files changed, 37 insertions, 4 deletions
diff --git a/gl/m4/getopt.m4 b/gl/m4/getopt.m4
index a19805e..5b211e5 100644
--- a/gl/m4/getopt.m4
+++ b/gl/m4/getopt.m4
@@ -1,4 +1,4 @@
1# getopt.m4 serial 24 1# getopt.m4 serial 28
2dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -79,8 +79,13 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
79 dnl Existence of the variable, in and of itself, is not a reason to replace 79 dnl Existence of the variable, in and of itself, is not a reason to replace
80 dnl getopt, but knowledge of the variable is needed to determine how to 80 dnl getopt, but knowledge of the variable is needed to determine how to
81 dnl reset and whether a reset reparses the environment. 81 dnl reset and whether a reset reparses the environment.
82 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then 82 dnl Solaris supports neither optreset nor optind=0, but keeps no state that
83 AC_CHECK_DECLS([optreset], [], [], 83 dnl needs a reset beyond setting optind=1; detect Solaris by getopt_clip.
84 if test -z "$gl_replace_getopt"; then
85 AC_CHECK_DECLS([optreset], [],
86 [AC_CHECK_DECLS([getopt_clip], [], [],
87 [[#include <getopt.h>]])
88 ],
84 [[#include <getopt.h>]]) 89 [[#include <getopt.h>]])
85 fi 90 fi
86 91
@@ -89,6 +94,10 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
89 dnl is left over from earlier calls, and neither setting optind = 0 nor 94 dnl is left over from earlier calls, and neither setting optind = 0 nor
90 dnl setting optreset = 1 get rid of this internal state. 95 dnl setting optreset = 1 get rid of this internal state.
91 dnl POSIX is silent on optind vs. optreset, so we allow either behavior. 96 dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
97 dnl POSIX 2008 does not specify leading '+' behavior, but see
98 dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on
99 dnl the next version of POSIX. For now, we only guarantee leading '+'
100 dnl behavior with getopt-gnu.
92 if test -z "$gl_replace_getopt"; then 101 if test -z "$gl_replace_getopt"; then
93 AC_CACHE_CHECK([whether getopt is POSIX compatible], 102 AC_CACHE_CHECK([whether getopt is POSIX compatible],
94 [gl_cv_func_getopt_posix], 103 [gl_cv_func_getopt_posix],
@@ -99,7 +108,7 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
99#include <stdlib.h> 108#include <stdlib.h>
100#include <string.h> 109#include <string.h>
101 110
102#if !HAVE_DECL_OPTRESET 111#if !HAVE_DECL_OPTRESET && !HAVE_DECL_GETOPT_CLIP
103# define OPTIND_MIN 0 112# define OPTIND_MIN 0
104#else 113#else
105# define OPTIND_MIN 1 114# define OPTIND_MIN 1
@@ -167,6 +176,20 @@ main ()
167 if (!(optind == 1)) 176 if (!(optind == 1))
168 return 12; 177 return 12;
169 } 178 }
179 /* Detect MacOS 10.5 bug. */
180 {
181 char *argv[3] = { "program", "-ab", NULL };
182 optind = OPTIND_MIN;
183 opterr = 0;
184 if (getopt (2, argv, "ab:") != 'a')
185 return 13;
186 if (getopt (2, argv, "ab:") != '?')
187 return 14;
188 if (optopt != 'b')
189 return 15;
190 if (optind != 2)
191 return 16;
192 }
170 193
171 return 0; 194 return 0;
172} 195}
@@ -174,6 +197,7 @@ main ()
174 [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no], 197 [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no],
175 [case "$host_os" in 198 [case "$host_os" in
176 mingw*) gl_cv_func_getopt_posix="guessing no";; 199 mingw*) gl_cv_func_getopt_posix="guessing no";;
200 darwin*) gl_cv_func_getopt_posix="guessing no";;
177 *) gl_cv_func_getopt_posix="guessing yes";; 201 *) gl_cv_func_getopt_posix="guessing yes";;
178 esac 202 esac
179 ]) 203 ])
@@ -234,6 +258,15 @@ main ()
234 if (getopt (3, argv, "-p") != 'p') 258 if (getopt (3, argv, "-p") != 'p')
235 return 7; 259 return 7;
236 } 260 }
261 /* This code fails on glibc 2.11. */
262 {
263 char *argv[] = { "program", "-b", "-a", NULL };
264 optind = opterr = 0;
265 if (getopt (3, argv, "+:a:b") != 'b')
266 return 8;
267 if (getopt (3, argv, "+:a:b") != ':')
268 return 9;
269 }
237 return 0; 270 return 0;
238 ]])], 271 ]])],
239 [gl_cv_func_getopt_gnu=yes], 272 [gl_cv_func_getopt_gnu=yes],