Find this topic in DOCUMENT of GNU C library: libc
http://www.gnu.org/software/libc/manual/ From page 633
Here I conclude some useful tips:
== return values of getopt():
- successful
- a character (the option name without argument)
- a character (the option name), a pointer to char (char *optarg: argument)
- failed
- '?' (not included in options OR missing argument) (int optopt keeps the character)
- -1 complete
== return values of getopt_long ():
- successful
- short_options
- (same with getopt())
- long_options
- content of val (flag = NULL) (Tips, put corresponding short option char in val)
- 0 (flag != NULL, put content of val into *flag)
- (same with above two) (with argument are stored in optarg)
- failed
- (same with getopt())
- -1 complete
PS: indexptr record the index of the options in array of struct option.
No comments:
Post a Comment