summaryrefslogtreecommitdiff
path: root/mysys/my_getopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r--mysys/my_getopt.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 6a7ee748930..5c7e3ecef34 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -100,10 +100,10 @@ static void default_reporter(enum loglevel level,
one. Call function 'get_one_option()' once for each option.
*/
-static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *);
+static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *);
void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint,
- const struct my_option *))
+ const struct my_option *, int *))
{
getopt_get_addr= func_addr;
}
@@ -362,8 +362,12 @@ int handle_options(int *argc, char ***argv,
my_progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
+ error= 0;
value= optp->var_type & GET_ASK_ADDR ?
- (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp) : optp->value;
+ (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp, &error) :
+ optp->value;
+ if (error)
+ return error;
if (optp->arg_type == NO_ARG)
{
@@ -397,9 +401,10 @@ invalid value '%s'",
my_progname, optp->name, optend);
continue;
}
- get_one_option(optp->id, optp,
- *((my_bool*) value) ?
- (char*) "1" : disabled_my_option);
+ if (get_one_option(optp->id, optp,
+ *((my_bool*) value) ?
+ (char*) "1" : disabled_my_option))
+ return EXIT_UNSPECIFIED_ERROR;
continue;
}
argument= optend;
@@ -457,7 +462,8 @@ invalid value '%s'",
optp->arg_type == NO_ARG)
{
*((my_bool*) optp->value)= (my_bool) 1;
- get_one_option(optp->id, optp, argument);
+ if (get_one_option(optp->id, optp, argument))
+ return EXIT_UNSPECIFIED_ERROR;
continue;
}
else if (optp->arg_type == REQUIRED_ARG ||
@@ -476,7 +482,8 @@ invalid value '%s'",
{
if (optp->var_type == GET_BOOL)
*((my_bool*) optp->value)= (my_bool) 1;
- get_one_option(optp->id, optp, argument);
+ if (get_one_option(optp->id, optp, argument))
+ return EXIT_UNSPECIFIED_ERROR;
continue;
}
/* Check if there are more arguments after this one */
@@ -501,7 +508,8 @@ invalid value '%s'",
my_progname, argument, optp->name);
return error;
}
- get_one_option(optp->id, optp, argument);
+ if (get_one_option(optp->id, optp, argument))
+ return EXIT_UNSPECIFIED_ERROR;
break;
}
}
@@ -524,7 +532,8 @@ invalid value '%s'",
my_progname, argument, optp->name);
return error;
}
- get_one_option(optp->id, optp, argument);
+ if (get_one_option(optp->id, optp, argument))
+ return EXIT_UNSPECIFIED_ERROR;
(*argc)--; /* option handled (short or long), decrease argument count */
}
@@ -1085,7 +1094,7 @@ static void init_variables(const struct my_option *options,
if (options->value)
init_one_value(options, options->value, options->def_value);
if (options->var_type & GET_ASK_ADDR &&
- (variable= (*getopt_get_addr)("", 0, options)))
+ (variable= (*getopt_get_addr)("", 0, options, 0)))
init_one_value(options, variable, options->def_value);
}
DBUG_VOID_RETURN;
@@ -1189,7 +1198,7 @@ void my_print_variables(const struct my_option *options)
for (optp= options; optp->id; optp++)
{
uchar* *value= (optp->var_type & GET_ASK_ADDR ?
- (*getopt_get_addr)("", 0, optp) : optp->value);
+ (*getopt_get_addr)("", 0, optp, 0) : optp->value);
if (value)
{
printf("%s ", optp->name);