Node:Getopt Long Options, Next:Getopt Long Option Example, Previous:Example of Getopt, Up:Getopt
getopt_longTo accept GNU-style long options as well as single-character options,
use getopt_long instead of getopt. This function is
declared in getopt.h, not unistd.h. You should make every
program accept long options if it uses any options, for this takes
little extra work and helps beginners remember how to use the program.
| struct option | Data Type |
This structure describes a single long option name for the sake of
getopt_long. The argument longopts must be an array of
these structures, one for each long option. Terminate the array with an
element containing all zeros.
The
|
| int getopt_long (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *indexptr) | Function |
Decode options from the vector argv (whose length is argc).
The argument shortopts describes the short options to accept, just as
it does in getopt. The argument longopts describes the long
options to accept (see above).
When When If If For any long option, When a long option has an argument, When |
Since long option names were used before before the getopt_long
options was invented there are program interfaces which require programs
to recognize options like -option value instead of
--option value. To enable these programs to use the GNU
getopt functionality there is one more function available.
| int getopt_long_only (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *indexptr) | Function |
|
The Assuming app -foo the |