getopt required_argument (Was Re: regtool - 1.8 - Core dump)

Igor Pechtchanski
Mon Feb 28 09:42:00 GMT 2005

On Sat, 26 Feb 2005, Brian Dessent wrote:

> Alexander Joerg Herrmann wrote:
> > What I was mentioning is that
> > regtool -K
> > causes a core fault and something similar under windows because the
> > argument is broken. I know that the argument is missing and so should
> > regtool. It should produce a usage message insteed of a crash imo.
> The program should not core dump on invalid arguments.  That I agree
> with, and it's a bug that should be fixed.

Well, it's just a matter of adding a check for optarg being NULL and
printing an appropriate message (e.g.,
          if (optarg == NULL) {
            fprintf(stderr, "Missing key-value separator\n");

However, the question is what should getopt's behavior be if something
specified as a "required_argument" is missing?  Should it simply set
optarg to NULL, just like it does with "optional_argument", or should it
return an error code of some sort?  Any getopt experts out there?
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list