Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does getopt_long store an unrecognized option?

Tags:

c

getopt-long

When getopt or getopt_long encounters an illegal option, it stores the offending option character in optopt. When the illegal option is a long option, where can I find out what the option was? And does anything meaningful get stored in optopt then?

I've set opterr = 0 to suppress the automatically printed error message. I want to create my own message that I can print or log where I'd like, but I want to include the name of the unrecognized option.

like image 634
Rob Kennedy Avatar asked Apr 27 '10 18:04

Rob Kennedy


1 Answers

The closest I can find is that if you get a BADCH return the argv item that caused it is in argv[optind-1]. Seems like there should be a better way to find the problem argument.

like image 154
Michael Burr Avatar answered Sep 19 '22 18:09

Michael Burr