summaryrefslogtreecommitdiff
path: root/mysys/my_getopt.c
diff options
context:
space:
mode:
authorunknown <jani@rhols221.adsl.netsonic.fi>2002-06-03 03:02:32 +0300
committerunknown <jani@rhols221.adsl.netsonic.fi>2002-06-03 03:02:32 +0300
commitc472a17db52851909d56400848131e0316ab6cd4 (patch)
tree227ea673a796a06ee8794106f507e5d0437d5308 /mysys/my_getopt.c
parent7cb2e2d1dce2c7466388f4a6ade0614564be82fc (diff)
downloadmariadb-git-c472a17db52851909d56400848131e0316ab6cd4.tar.gz
Fixed two bugs in my_getopt.
mysys/my_getopt.c: Fixed two bugs in my_getopt: - argc was decremented twice when type was GET_BOOL and short option was used. This caused all GET_BOOL -type short-options to malfunction. - Fixed a bug in argv handling. Any program that used argv directly without checking argc first, tried to use (already handled) options as non-option arguments, after all true non-option arguments were handled. At least mysqldump was affected by this bug.
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r--mysys/my_getopt.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 76cdbede78d..12af811a0c8 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -68,7 +68,7 @@ int handle_options(int *argc, char ***argv,
{
uint opt_found, argvpos= 0, length, spec_len, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
- option_is_loose;
+ option_is_loose, option_used= 0;
char *progname= *(*argv), **pos, *optend, *prev_found;
const struct my_option *optp;
int error;
@@ -84,6 +84,7 @@ int handle_options(int *argc, char ***argv,
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
{
char *argument= 0;
+ option_used= 1;
must_be_var= 0;
set_maximum_value= 0;
special_used= 0;
@@ -336,7 +337,6 @@ int handle_options(int *argc, char ***argv,
if (optp->var_type == GET_BOOL && optp->arg_type == NO_ARG)
{
*((my_bool*) optp->value)= (my_bool) 1;
- (*argc)--;
continue; // For GET_BOOL get_one_option() shouldn't be called
}
else if (optp->arg_type == REQUIRED_ARG ||
@@ -401,6 +401,12 @@ int handle_options(int *argc, char ***argv,
else /* non-option found */
(*argv)[argvpos++]= cur_arg;
}
+ /* Destroy the first, already handled option, so that programs that look
+ for arguments in 'argv', without checking 'argc', know when to stop.
+ Items in argv, before the destroyed one, are all non-option -arguments
+ to the program, yet to be (possibly) handled. */
+ if (option_used)
+ (*argv)[argvpos]= 0;
return 0;
}