test-getopt: test stderr behavior
[gnulib.git] / doc / posix-functions / getopt.texi
1 @node getopt
2 @section @code{getopt}
3 @findex getopt
4
5 POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/getopt.html}
6
7 Gnulib module: getopt-posix or getopt-gnu
8
9 The module @code{getopt-gnu} has support for ``long options'' and for
10 ``options that take optional arguments''.  Compared to the API defined by POSIX,
11 it adds a header file @code{<getopt.h>} and a function @code{getopt_long}.
12
13 Portability problems fixed by either Gnulib module @code{getopt-posix} or @code{getopt-gnu}:
14 @itemize
15 @item
16 The @code{getopt} function keeps some internal state that cannot be explicitly
17 reset on some platforms:
18 mingw.
19 @end itemize
20
21 Portability problems fixed by Gnulib module @code{getopt-gnu}:
22 @itemize
23 @item
24 The function @code{getopt} does not support the @samp{+} flag in the options
25 string on some platforms:
26 MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10.
27 @item
28 The function @code{getopt} does not obey the @samp{-} flag in the options
29 string when @env{POSIXLY_CORRECT} is set on some platforms:
30 Cygwin 1.7.0.
31 @item
32 The function @code{getopt} does not support options with optional arguments
33 on some platforms:
34 MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11, IRIX 6.5, OSF/1 5.1,
35 Solaris 10, Cygwin 1.5.x.
36 @item
37 The function @code{getopt_long} is missing on some platforms:
38 AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Interix 3.5.
39 @item
40 The function @code{getopt_long_only} is missing on some platforms:
41 MacOS X 10.3, FreeBSD 5.2.1, NetBSD 3.0, AIX 5.1, HP-UX 11, IRIX 6.5,
42 OSF/1 5.1, Solaris 9, mingw, Interix 3.5.
43 @end itemize
44
45 Portability problems not fixed by Gnulib:
46 @itemize
47 @item
48 The default behavior of the glibc implementation of @code{getopt} allows
49 mixing option and non-option arguments on the command line in any order.
50 Other implementations, such as the one in Cygwin, enforce strict POSIX
51 compliance: they require that the option arguments precede the non-option
52 arguments.  This is something to watch out in your program's
53 testsuite.
54 @item
55 The glibc implementation allows a complete reset of the environment,
56 including re-checking for @env{POSIXLY_CORRECT}, by setting
57 @code{optind} to 0.  Other implementations provide @code{optreset},
58 causing a reset by setting it non-zero, although it does not
59 necessarily re-read @env{POSIXLY_CORRECT}.
60 @item
61 Mixing a leading @samp{-} or @samp{+} with a leading @samp{:} in the
62 optstring argument has inconsistent effects across platforms.
63 @end itemize