Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
wsgetopt.h
1 /*
2  Declarations for getopt.
3  Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2009,2010
4  Free Software Foundation, Inc.
5  This file is part of the GNU C Library.
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later */
8 
9 #ifndef _GETOPT_H
10 
11 #ifndef __need_getopt
12 # define _GETOPT_H 1
13 #endif
14 
15 #include "ws_symbol_export.h"
16 
17 #ifndef __THROW
18 # ifndef __GNUC_PREREQ
19 # define __GNUC_PREREQ(maj, min) (0)
20 # endif
21 # if defined __cplusplus && __GNUC_PREREQ (2,8)
22 # define __THROW throw ()
23 # else
24 # define __THROW
25 # endif
26 #endif
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /* For communication from `getopt' to the caller.
33  When `getopt' finds an option that takes an argument,
34  the argument value is returned here.
35  Also, when `ordering' is RETURN_IN_ORDER,
36  each non-option ARGV-element is returned here. */
37 
38 WS_DLL_PUBLIC char *optarg;
39 
40 /* Index in ARGV of the next element to be scanned.
41  This is used for communication to and from the caller
42  and for communication between successive calls to `getopt'.
43 
44  On entry to `getopt', zero means this is the first call; initialize.
45 
46  When `getopt' returns -1, this is the index of the first of the
47  non-option elements that the caller should itself scan.
48 
49  Otherwise, `optind' communicates from one call to the next
50  how much of ARGV has been scanned so far. */
51 
52 WS_DLL_PUBLIC int optind;
53 
54 /* Callers store zero here to inhibit the error message `getopt' prints
55  for unrecognized options. */
56 
57 WS_DLL_PUBLIC int opterr;
58 
59 /* Set to an option character which was unrecognized. */
60 
61 WS_DLL_PUBLIC int optopt;
62 
63 #ifndef __need_getopt
64 /* Describe the long-named options requested by the application.
65  The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
66  of `struct option' terminated by an element containing a name which is
67  zero.
68 
69  The field `has_arg' is:
70  no_argument (or 0) if the option does not take an argument,
71  required_argument (or 1) if the option requires an argument,
72  optional_argument (or 2) if the option takes an optional argument.
73 
74  If the field `flag' is not NULL, it points to a variable that is set
75  to the value given in the field `val' when the option is found, but
76  left unchanged if the option is not found.
77 
78  To have a long-named option do something other than set an `int' to
79  a compiled-in constant, such as set a value from `optarg', set the
80  option's `flag' field to zero and its `val' field to a nonzero
81  value (the equivalent single-letter option character, if there is
82  one). For long options that have a zero `flag' field, `getopt'
83  returns the contents of the `val' field. */
84 
85 struct option
86 {
87  const char *name;
88  /* has_arg can't be an enum because some compilers complain about
89  type mismatches in all the code that assumes it is an int. */
90  int has_arg;
91  int *flag;
92  int val;
93 };
94 
95 /* Names for the values of the `has_arg' field of `struct option'. */
96 
97 # define no_argument 0
98 # define required_argument 1
99 # define optional_argument 2
100 #endif /* need getopt */
101 
102 
103 /* Get definitions and prototypes for functions to process the
104  arguments in ARGV (ARGC of them, minus the program name) for
105  options given in OPTS.
106 
107  Return the option character from OPTS just read. Return -1 when
108  there are no more options. For unrecognized options, or options
109  missing arguments, `optopt' is set to the option letter, and '?' is
110  returned.
111 
112  The OPTS string is a list of characters which are recognized option
113  letters, optionally followed by colons, specifying that that letter
114  takes an argument, to be placed in `optarg'.
115 
116  If a letter in OPTS is followed by two colons, its argument is
117  optional. This behavior is specific to the GNU `getopt'.
118 
119  The argument `--' causes premature termination of argument
120  scanning, explicitly telling `getopt' that there are no more
121  options.
122 
123  If OPTS begins with `--', then non-option arguments are treated as
124  arguments to the option '\0'. This behavior is specific to the GNU
125  `getopt'. */
126 
127 #ifdef __GNU_LIBRARY__
128 /* Many other libraries have conflicting prototypes for getopt, with
129  differences in the consts, in stdlib.h. To avoid compilation
130  errors, only prototype getopt for the GNU C library. */
131 WS_DLL_PUBLIC int getopt (int ___argc, char *const *___argv, const char *__shortopts)
132  __THROW;
133 
134 # if defined __need_getopt && defined __USE_POSIX2 \
135  && !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
136 /* The GNU getopt has more functionality than the standard version. The
137  additional functionality can be disable at runtime. This redirection
138  helps to also do this at runtime. */
139 # ifdef __REDIRECT
140  extern int __REDIRECT_NTH (getopt, (int ___argc, char *const *___argv,
141  const char *__shortopts),
142  __posix_getopt);
143 # else
144 extern int __posix_getopt (int ___argc, char *const *___argv,
145  const char *__shortopts) __THROW;
146 # define getopt __posix_getopt
147 # endif
148 # endif
149 #else /* not __GNU_LIBRARY__ */
150 WS_DLL_PUBLIC int getopt (int ___argc, char *const *___argv,
151  const char *__shortopts);
152 #endif /* __GNU_LIBRARY__ */
153 
154 #ifndef __need_getopt
155 WS_DLL_PUBLIC int getopt_long (int ___argc, char *const *___argv,
156  const char *__shortopts,
157  const struct option *__longopts, int *__longind)
158  __THROW;
159 extern int getopt_long_only (int ___argc, char *const *___argv,
160  const char *__shortopts,
161  const struct option *__longopts, int *__longind)
162  __THROW;
163 
164 #endif
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 /* Make sure we later can get all the definitions and declarations. */
171 #undef __need_getopt
172 
173 #endif /* getopt.h */
Definition: pcapng.c:148