[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

getopt and getopt_long not working properly?



Hi!

This is so weird that I already spect a "that's the way they are supposed to
work", but just in case, here it goes...

I'm working in an extension to the debian mbr to fix a Y2K problem some bios
from the 95's have.

I have an option (-y or --y2kbug) to wich I want to pass an optional
argument (u|l), so I define the long_options entry like this:
{"y2kbug", 2, 0, 'y'} and call getopt_long with:
(argc, argv, "fI:klno:y::P:rT:vVhd:e:i:p:t:", ong_options, &long_index)
everything like we have on actual mbr but adding the "y::" option.

The thing is that if I put the parameter and the option together like in
"-yu" it works ok, the "u" is passed in optarg, but if I put them with an
space in the middle, like "-y u" then optarg is NULL, same happens with the
long option, "--y2kbug=u" works but "--y2kbug u" doesn't.

This behaviour is only if you define the parameter of the option optional,
if you define it required it works ok.

Am I doing somthing wrong?
Is this really working likt it should?
Is there a bug?

Regards...
-- 
Manty/BestiaTester -> http://manty.net



Reply to: