2 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
3 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5 * This software is available to you under the OpenIB.org BSD license
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the following
12 * - Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the following
16 * - Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 /* the string argument that came with the option */
39 /* Index in ARGV of the next element to be scanned.
41 When `getopt' returns -1, this is the index of the first of the
42 non-option elements that the caller should itself scan.
44 Otherwise, `optind' communicates from one call to the next
45 how much of ARGV has been scanned so far. */
49 /* Callers store zero here to inhibit the error message `getopt' prints
50 for unrecognized options. */
54 /* Set to an option character which was unrecognized. */
57 /* Describe the long-named options requested by the application.
58 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
59 of `struct option' terminated by an element containing a name which is
62 The field `has_arg' is:
63 no_argument (or 0) if the option does not take an argument,
64 required_argument (or 1) if the option requires an argument,
65 optional_argument (or 2) if the option takes an optional argument.
67 If the field `flag' is not NULL, it points to a variable that is set
68 to the value given in the field `val' when the option is found, but
69 left unchanged if the option is not found.
71 To have a long-named option do something other than set an `int' to
72 a compiled-in constant, such as set a value from `optarg', set the
73 option's `flag' field to zero and its `val' field to a nonzero
74 value (the equivalent single-letter option character, if there is
75 one). For long options that have a zero `flag' field, `getopt'
76 returns the contents of the `val' field. */
86 /* Names for the values of the `has_arg' field of `struct option'. */
88 #define required_argument 1
89 #define optional_argument 2
91 /* Return the option character from OPTS just read. Return -1 when
92 there are no more options. For unrecognized options, or options
93 missing arguments, `optopt' is set to the option letter, and '?' is
96 The OPTS string is a list of characters which are recognized option
97 letters, optionally followed by colons, specifying that that letter
98 takes an argument, to be placed in `optarg'.
100 If a letter in OPTS is followed by two colons, its argument is
101 optional. This behavior is specific to the GNU `getopt'.
103 The argument `--' causes premature termination of argument
104 scanning, explicitly telling `getopt' that there are no more
107 If OPTS begins with `--', then non-option arguments are treated as
108 arguments to the option '\0'. This behavior is specific to the GNU
111 extern int getopt(int argc, char *const *argv, const char *shortopts);
112 extern int getopt_long(int argc, char *const*argv,
113 const char *optstring,
114 const struct option *longopts, int *longindex);