poll tests: Avoid test failure on BSD and Solaris systems.
[gnulib.git] / doc / posix-functions / getopt.texi
blob7c9ab31c23c7b6edbd049ab282e8d3477ccc5666
1 @node getopt
2 @section @code{getopt}
3 @findex getopt
5 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html}
7 LSB specification:@* @url{https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/libutil-getopt-3.html}
9 Gnulib module: getopt-posix or getopt-gnu
11 The module @code{getopt-gnu} has support for ``long options'' and for
12 ``options that take optional arguments''.  Compared to the API defined by POSIX,
13 it adds a header file @code{<getopt.h>} and a function @code{getopt_long}.
15 Portability problems fixed by either Gnulib module @code{getopt-posix} or @code{getopt-gnu}:
16 @itemize
17 @item
18 This function is missing on some platforms:
19 MSVC 14.
20 @item
21 The value of @code{optind} after a missing required argument is wrong
22 on some platforms:
23 Mac OS X 10.13, AIX 7.1, mingw.
24 @end itemize
26 Portability problems fixed by Gnulib module @code{getopt-gnu}:
27 @itemize
28 @item
29 The function @code{getopt} does not support the @samp{+} flag in the options
30 string on some platforms:
31 Mac OS X 10.13, AIX 5.2, HP-UX 11, IRIX 6.5, Solaris 11 2010-11.
32 @item
33 The function @code{getopt} does not obey the combination of @samp{+}
34 and @samp{:} flags in the options string on some platforms:
35 glibc 2.11.
36 @item
37 The function @code{getopt} does not obey the @samp{-} flag in the options
38 string when @env{POSIXLY_CORRECT} is set on some platforms:
39 Cygwin 1.7.0.
40 @item
41 The function @code{getopt} does not support options with optional arguments
42 on some platforms:
43 Mac OS X 10.13, OpenBSD 4.0, AIX 5.2, HP-UX 11, IRIX 6.5, Solaris 11 2010-11, Cygwin 1.5.x.
44 @item
45 The function @code{getopt_long} is missing on some platforms:
46 AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, MSVC 14.
47 @item
48 The function @code{getopt_long} does not support abbreviated long options
49 where all disambiguations are equivalent on some platforms:
50 OpenBSD 5.0.
51 @item
52 The function @code{getopt_long_only} is missing on some platforms:
53 FreeBSD 5.2.1, NetBSD 9.0, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, mingw, MSVC 14.
54 @item
55 This function crashes if the option string includes @code{W;} on some
56 platforms:
57 glibc 2.14.
58 @end itemize
60 Portability problems not fixed by Gnulib:
61 @itemize
62 @item
63 The default behavior of the glibc implementation of @code{getopt} allows
64 mixing option and non-option arguments on the command line in any order.
65 Other implementations, such as the one in Cygwin, enforce strict POSIX
66 compliance: they require that the option arguments precede the non-option
67 arguments.  This is something to watch out in your program's
68 testsuite.
69 @item
70 The glibc implementation allows a complete reset of the environment,
71 including re-checking for @env{POSIXLY_CORRECT}, by setting
72 @code{optind} to 0.  Several BSD implementations provide @code{optreset},
73 causing a reset by setting it non-zero, although it does not
74 necessarily re-read @env{POSIXLY_CORRECT}.  Solaris @code{getopt} does
75 not support either reset method, but does not maintain state that
76 needs the extra level of reset.
77 @item
78 On some platforms, this function does not set the stream error
79 indicator on attempts to write to a read-only stream:
80 glibc 2.13, Cygwin 1.7.9.
81 @end itemize