Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

getopt(3) Guardian Native C Library Calls Reference Manual
NAME
getopt - Gets ag letters from the argument vector
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
H-series OSS processes: /G/system/zdllnnn/zcrtldll
SYNOPSIS
#include <unistd.h>
int getopt(
int argc,
const char * const argv[],
const char *optstring);
extern char *optarg;
extern int optind;
extern int opterr;
extern int optopt;
PARAMETERS
argc Species the number of parameters passed to the routine.
argv Points to an array of argc pointers to argument strings.
optstring Species a string of recognized ag characters. If a character is followed by a :
(colon), the ag is expected to take a parameter that may or may not be separated
from it by white space.
DESCRIPTION
The getopt() function parses argument lists. It returns the next ag character in the argv parame-
ter list that matches a character in the optstring parameter. If that ag takes an argument, the
getopt() function has the optarg variable point to the ag argument according to the following
rules:
If the ag is the last character pointed at by an argv element, optarg will contain argvs
next element, and optind is incremented by 2. The getopt() function returns an error if
the resulting optind is greater than or equal to argc.
If the ag is not the last character, then the optarg variable points at the string after the
ag character in the associated element of argv. The optind variable is incremented by
1.
The optarg external variable is set to point to the start of the ags parameter on return from the
getopt() function.
The getopt() function places the argv index of the next argument to be processed in optind. The
optind variable is externally initialized to 1 before the rst call to getopt() so that argv[0] is not
processed. Error messages can be suppressed by providing a value of 0 (zero) as the opterr
parameter.
EXAMPLES
The following example shows a suggested way to use the getopt() function.
#include <unistd.h>
main(argc, argv)
int argc;
char *argv[];
324 Hewlett-Packard Company 527192-005