DESCRIPTION
The getopt_long function is similar to getopt(3) but it accepts options in two forms: words and characters. The getopt_long function provides a superset of the functionality of getopt(3). The getopt_long function can be used in two ways. In the first way, every long option understood by the program has a corresponding short option, and the option structure is only used to translate from long options to short options. When used in this fashion, getopt_long behaves identically to getopt(3). This is a good way to add long option processing to an existing program with the minimum of rewriting. In the second mechanism, a long option sets a flag in the
.Vt option structure passed, or will store a pointer to the command line argument in the
.Vt option structure passed to it for options that take arguments. Additionally, the long options argument may be specified as a single argument with an equal sign, e.g.,
"myprogram --myoption=somevalue"
When a long option is processed, the call to getopt_long will return 0. For this reason, long option processing without shortcuts is not backwards compatible with getopt(3).
It is possible to combine these methods, providing for long options processing with short option equivalents for some options. Less frequently used options would be processed as long options only.
The getopt_long call requires a structure to be initialized describing the long options. The structure is:
struct option {
char *name;
int has_arg;
int *flag;
int val;
};
The name field should contain the option name without the leading double dash.
The has_arg field should be one of: