summaryrefslogtreecommitdiffstats
path: root/gl/getopt-ext.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/getopt-ext.h')
-rw-r--r--gl/getopt-ext.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/gl/getopt-ext.h b/gl/getopt-ext.h
new file mode 100644
index 0000000..d37c293
--- /dev/null
+++ b/gl/getopt-ext.h
@@ -0,0 +1,77 @@
1/* Declarations for getopt (GNU extensions).
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library and is also part of gnulib.
4 Patches to this file should be submitted to both projects.
5
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.
10
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.
15
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 <https://www.gnu.org/licenses/>. */
19
20#ifndef _GETOPT_EXT_H
21#define _GETOPT_EXT_H 1
22
23/* This header should not be used directly; include getopt.h instead.
24 Unlike most bits headers, it does not have a protective #error,
25 because the guard macro for getopt.h in gnulib is not fixed. */
26
27__BEGIN_DECLS
28
29/* Describe the long-named options requested by the application.
30 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
31 of 'struct option' terminated by an element containing a name which is
32 zero.
33
34 The field 'has_arg' is:
35 no_argument (or 0) if the option does not take an argument,
36 required_argument (or 1) if the option requires an argument,
37 optional_argument (or 2) if the option takes an optional argument.
38
39 If the field 'flag' is not NULL, it points to a variable that is set
40 to the value given in the field 'val' when the option is found, but
41 left unchanged if the option is not found.
42
43 To have a long-named option do something other than set an 'int' to
44 a compiled-in constant, such as set a value from 'optarg', set the
45 option's 'flag' field to zero and its 'val' field to a nonzero
46 value (the equivalent single-letter option character, if there is
47 one). For long options that have a zero 'flag' field, 'getopt'
48 returns the contents of the 'val' field. */
49
50struct option
51{
52 const char *name;
53 /* has_arg can't be an enum because some compilers complain about
54 type mismatches in all the code that assumes it is an int. */
55 int has_arg;
56 int *flag;
57 int val;
58};
59
60/* Names for the values of the 'has_arg' field of 'struct option'. */
61
62#define no_argument 0
63#define required_argument 1
64#define optional_argument 2
65
66extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
67 const char *__shortopts,
68 const struct option *__longopts, int *__longind)
69 __THROW _GL_ARG_NONNULL ((2, 3));
70extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
71 const char *__shortopts,
72 const struct option *__longopts, int *__longind)
73 __THROW _GL_ARG_NONNULL ((2, 3));
74
75__END_DECLS
76
77#endif /* _GETOPT_EXT_H */