Special portable re-entrant version of getopt.
More...
|
int | bu_getopt (int nargc, char *const nargv[], const char *ostr) |
|
Special portable re-entrant version of getopt.
Everything is prefixed with bu_, to distinguish it from the various getopt routines found in libc.
Important note - If bu_getopt() is going to be used more than once, it is necessary to reinitialize bu_optind=1 before beginning on the next argument list.
◆ bu_getopt()
int bu_getopt |
( |
int |
nargc, |
|
|
char *const |
nargv[], |
|
|
const char * |
ostr |
|
) |
| |
Get option letter from argument vector.
- Parameters
-
nargc | number of arguments |
nargv | array of argument strings |
ostr | option string |
The 'ostr' option string may contain individual characters (e.g., "abc"), characters followed by a colon to indicate a required argument (e.g., "a:bc", 'a' requires an argument, 'b' and 'c' do not), and characters followed by two colons to indicate an optional argument (e.g., "ab::c", 'b' may be followed by an argument, but none require an argument).
Returns -1 when the argument list is exhausted, otherwise it returns the next known option character. If bu_getopt() encounters a character not found in ostr or if it detects a required missing option argument, it returns ‘?’ (question mark). If ostr has a leading ‘:’ then a missing option argument causes ‘:’ to be returned instead of ‘?’. In either case, the variable bu_optopt is set to the character that caused the error.
◆ bu_opterr
◆ bu_optind
for bu_getopt(). current index into parent argv vector.
◆ bu_optopt
for bu_getopt(). current option being checked for validity.
◆ bu_optarg
for bu_getopt(). current argument associated with current option.