Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getsubopt - get suboptions from string

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

int getsubopt (char * *optionp, char * const *tokens, char * *valuep);

Description getsubopt() extracts subobtions from an option argument which was first processed by

getopt(). These suboptions must be separated by commas and can consist of either a
single token or a pair of token values separated by an equals sign. Because commas are
used to delimit suboptions in the option string, they must not be part of the suboption or the
value of a suboption. Similarly, a token must not contain an equals sign, because tokens
and associated values are separated by equals signs.

getsubopt() receives the address of a pointer to the option string which represents an
array of possible tokens and the address of a pointer to a value string. The index of the
token that corresponds to the suboption from the transferred string is returned; if no
corresponding suboption is found, -1 is returned. If the option string under *optionp only
contains one suboption, getsubopt() updates *optionp such that the null byte at the end
of the string is pointed to; otherwise, the suboption is isolated through replacement of the
separating comma being with a null byte, and *optionp points to the beginning of the next
suboption. If the suboption is assigned a value, getsubopt() updates *valuep such that
the first character of the value is pointed to. Otherwise, *valuep is set to zero.

The token array is organized as a sequence of pointers to null-terminated strings. The end
of the token array is identified by a null pointer.

If valuep is not zero, getsubopt() returns the suboption to which a value was assigned.
The calling program can use this information to determine whether the presence or the
omission of a value for this suboption represents an error.
If getsubopt() does not find a suboption in the tokens array, the calling program should
decide whether this means an error or whether the non-recognized option should be
passed to another program.

Return val.

Index of the matching token if successful.

-1                     if no matching token was found.

Notes

During processing of the token, commas in the option string are changed into null bytes.
Blanks in tokens or pairs of token values must be protected from shell by quotation marks.

See also

getopt(), stdlib.h