L4Re Operating System Framework
Interface and Usage Documentation
•All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
getopt.h
Go to the documentation of this file.
1
5/*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 * License: see LICENSE.spdx (in this directory or the directories above)
10 */
11#ifndef _GETOPT_H
12#define _GETOPT_H
13
14#ifndef NULL
15#define NULL 0
16#endif
17
18#include <l4/sys/compiler.h>
19
21
22/* For communication from `getopt' to the caller.
23 When `getopt' finds an option that takes an argument,
24 the argument value is returned here.
25 Also, when `ordering' is RETURN_IN_ORDER,
26 each non-option ARGV-element is returned here. */
27
28extern char *optarg;
29
30/* Index in ARGV of the next element to be scanned.
31 This is used for communication to and from the caller
32 and for communication between successive calls to `getopt'.
33
34 On entry to `getopt', zero means this is the first call; initialize.
35
36 When `getopt' returns -1, this is the index of the first of the
37 non-option elements that the caller should itself scan.
38
39 Otherwise, `optind' communicates from one call to the next
40 how much of ARGV has been scanned so far. */
41
42extern int optind;
43
44/* Callers store zero here to inhibit the error message `getopt' prints
45 for unrecognized options. */
46
47extern int opterr;
48
49/* Set to an option character which was unrecognized. */
50
51extern int optopt;
52
53/* Describe the long-named options requested by the application.
54 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
55 of `struct option' terminated by an element containing a name which is
56 zero.
57
58 The field `has_arg' is:
59 no_argument (or 0) if the option does not take an argument,
60 required_argument (or 1) if the option requires an argument,
61 optional_argument (or 2) if the option takes an optional argument.
62
63 If the field `flag' is not NULL, it points to a variable that is set
64 to the value given in the field `val' when the option is found, but
65 left unchanged if the option is not found.
66
67 To have a long-named option do something other than set an `int' to
68 a compiled-in constant, such as set a value from `optarg', set the
69 option's `flag' field to zero and its `val' field to a nonzero
70 value (the equivalent single-letter option character, if there is
71 one). For long options that have a zero `flag' field, `getopt'
72 returns the contents of the `val' field. */
73
74struct option
75{
76 const char *name;
77 /* has_arg can't be an enum because some compilers complain about
78 type mismatches in all the code that assumes it is an int. */
79 int has_arg;
80 int *flag;
81 int val;
82};
83
84/* Names for the values of the `has_arg' field of `struct option'. */
85
86#define no_argument 0
87#define required_argument 1
88#define optional_argument 2
89
90L4_CV int getopt (int argc, char *const *argv, const char *shortopts);
91
92L4_CV int getopt_long (int argc, char *const *argv, const char *shortopts,
93 const struct option *longopts, int *longind);
94L4_CV int getopt_long_only (int argc, char *const *argv,
95 const char *shortopts,
96 const struct option *longopts, int *longind);
97
98L4_CV int _getopt_internal (int argc, char *const *argv,
99 const char *shortopts,
100 const struct option *longopts, int *longind,
101 int long_only);
102
104
105#endif /* _GETOPT_H */
L4 compiler related defines.
#define __END_DECLS
End section with C types and functions.
Definition compiler.h:167
#define L4_CV
Define calling convention.
Definition linkage.h:33
#define __BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:164