unistd: allow to turn off getopt_long
[uclibc-ng.git] / libc / sysdeps / linux / common / bits / getopt.h
blobdababe07d5f5f1c4a9503f90763581b52e06a79d
1 /* Declarations for getopt.
2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _GETOPT_H
22 #include <features.h>
24 #ifndef __need_getopt
25 # define _GETOPT_H 1
26 #endif
28 __BEGIN_DECLS
30 /* For communication from `getopt' to the caller.
31 When `getopt' finds an option that takes an argument,
32 the argument value is returned here.
33 Also, when `ordering' is RETURN_IN_ORDER,
34 each non-option ARGV-element is returned here. */
36 extern char *optarg;
38 /* Index in ARGV of the next element to be scanned.
39 This is used for communication to and from the caller
40 and for communication between successive calls to `getopt'.
42 On entry to `getopt', zero means this is the first call; initialize.
44 When `getopt' returns -1, this is the index of the first of the
45 non-option elements that the caller should itself scan.
47 Otherwise, `optind' communicates from one call to the next
48 how much of ARGV has been scanned so far. */
50 extern int optind;
52 /* Callers store zero here to inhibit the error message `getopt' prints
53 for unrecognized options. */
55 extern int opterr;
57 /* Set to an option character which was unrecognized. */
59 extern int optopt;
61 #ifndef __need_getopt
62 /* Describe the long-named options requested by the application.
63 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
64 of `struct option' terminated by an element containing a name which is
65 zero.
67 The field `has_arg' is:
68 no_argument (or 0) if the option does not take an argument,
69 required_argument (or 1) if the option requires an argument,
70 optional_argument (or 2) if the option takes an optional argument.
72 If the field `flag' is not NULL, it points to a variable that is set
73 to the value given in the field `val' when the option is found, but
74 left unchanged if the option is not found.
76 To have a long-named option do something other than set an `int' to
77 a compiled-in constant, such as set a value from `optarg', set the
78 option's `flag' field to zero and its `val' field to a nonzero
79 value (the equivalent single-letter option character, if there is
80 one). For long options that have a zero `flag' field, `getopt'
81 returns the contents of the `val' field. */
83 struct option
85 const char *name;
86 /* has_arg can't be an enum because some compilers complain about
87 type mismatches in all the code that assumes it is an int. */
88 int has_arg;
89 int *flag;
90 int val;
93 /* Names for the values of the `has_arg' field of `struct option'. */
95 # define no_argument 0
96 # define required_argument 1
97 # define optional_argument 2
98 #endif /* need getopt */
101 /* Get definitions and prototypes for functions to process the
102 arguments in ARGV (ARGC of them, minus the program name) for
103 options given in OPTS.
105 Return the option character from OPTS just read. Return -1 when
106 there are no more options. For unrecognized options, or options
107 missing arguments, `optopt' is set to the option letter, and '?' is
108 returned.
110 The OPTS string is a list of characters which are recognized option
111 letters, optionally followed by colons, specifying that that letter
112 takes an argument, to be placed in `optarg'.
114 If a letter in OPTS is followed by two colons, its argument is
115 optional. This behavior is specific to the GNU `getopt'.
117 The argument `--' causes premature termination of argument
118 scanning, explicitly telling `getopt' that there are no more
119 options.
121 If OPTS begins with `--', then non-option arguments are treated as
122 arguments to the option '\0'. This behavior is specific to the GNU
123 `getopt'. */
125 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
126 __THROW;
127 libc_hidden_proto(getopt)
129 #if defined __UCLIBC_HAS_GETOPT_LONG__
130 #ifndef __need_getopt
131 extern int getopt_long (int ___argc, char *const *___argv,
132 const char *__shortopts,
133 const struct option *__longopts, int *__longind)
134 __THROW;
135 extern int getopt_long_only (int ___argc, char *const *___argv,
136 const char *__shortopts,
137 const struct option *__longopts, int *__longind)
138 __THROW;
140 #endif
141 #endif
143 __END_DECLS
145 /* Make sure we later can get all the definitions and declarations. */
146 #undef __need_getopt
148 #endif /* getopt.h */