I use getopt_long
on GNU/Linux machine.
Initialize options list as:
static struct option long_options[] = {
{"mode", required_argument, 0, 9},
{0, 0, 0, 0}
};
Have following line of code
c = getopt_long(argc, argv, "", long_options, index_ptr);
When I run my program with command:
prog --mode
Above shown line of code returns '?' in c, but not ':' as expected according to getopt(3)
man page: "Error and -1 returns are the
same as for getopt()"
Yes, when using/parsing short options one could write in options list something like ":m:", so that variable c on missing argument would contain ':', not '?', but what one should do to distinguish between two cases(missing argument, invalid option) when parsing only long options?
How could one distinguish between invalid option and option with missing required argument?