getopt_long_only

Retrieves long arguments from a command line argument list.

Library:LibC
Classification:GNU
Service:General C Services

Syntax

  #include <getopt.h> 
   
  int getopt_long_only   (
     int                    argc,
     char * const           argv[],
     const char            *optstring,
     const struct option   *longopts,
     int                   *longindex);
  

Parameters

argc

(IN) Specifies the length of the argv parameter.

argv

(IN) Points to an array of options.

optstring

(IN) Points to which short options to accept.

longopts

(IN) Points to an array of option structures which specify which long options to accept. The last element in the array must be a zero filled option structure.

longindex

(OUT) Points to the index into the longopts array for the long option.

Return Values

When getopt_long_only has no more options to handle, it returns -1.

Remarks

The getopt_long_only function parses options passed with a single hyphen (-), first as a long option and if it is not found in the long option array, parses it as a short option. For example, if -fab is passed as the option, getopt_long_only looks for a long option named fab. If it is not found, then fab is parsed as three short options, -f, -a, and -b.

See Also