diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2021-11-18 17:19:52 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2021-11-18 17:25:41 +0100 |
commit | 220dc1fd59e61a44718a38ea59de5dc1da5aab8f (patch) | |
tree | feef9caf67b82bc40dca7d0926ffc54ae9af3f9d /mysys | |
parent | 2dcb823631c0395942072fc6b2bf471dc3280387 (diff) | |
download | mariadb-git-220dc1fd59e61a44718a38ea59de5dc1da5aab8f.tar.gz |
xxx
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_getopt.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 3fe025ba808..96f147c26c3 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -38,7 +38,7 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err); static void init_variables(const struct my_option *, init_func_p); static void init_one_value(const struct my_option *, void *, longlong); static void fini_one_value(const struct my_option *, void *, longlong); -static int setval(const struct my_option *, void *, char *, my_bool); +static int setval(const struct my_option *, void *, char *, my_bool, const char *); static char *check_struct_option(char *cur_arg, char *key_name); /* @@ -133,6 +133,48 @@ double getopt_ulonglong2double(ulonglong v) return u.dbl; } +#ifdef _WIN32 +/** + + On Windows, if program is running in UTF8 mode, but some arguments are not UTF8. + + This will mostly likely be a sign of old "ANSI" my.ini, and it is likely that + something will go wrong, e.g file access error. +*/ +static void validate_value(const char *key, const char *value, + const char *filename) +{ + MY_STRCOPY_STATUS status; + const struct charset_info_st *cs= &my_charset_utf8mb4_bin; + size_t len; + if (GetACP() != CP_UTF8) + return; + len= strlen(value); + if (!len) + return; + cs->cset->well_formed_char_length(cs, value, value + len, len, &status); + if (!status.m_well_formed_error_pos) + return; + + if (filename && *filename) + { + my_getopt_error_reporter(WARNING_LEVEL, + "%s: invalid (non-UTF8) characters found for option '%s'" + " in file '%s'", + my_progname, key, filename); + } + else + { + DBUG_ASSERT(0); + my_getopt_error_reporter( + WARNING_LEVEL, "%s: invalid (non-UTF8) characters for option %s", + my_progname, key); + } +} +#else +#define validate_value(key, value, filename) (void)filename +#endif + /** Handle command line options. Sort options. @@ -564,7 +606,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, } } if ((error= setval(optp, optp->value, argument, - set_maximum_value))) + set_maximum_value,filename))) DBUG_RETURN(error); if (get_one_option(optp, argument, filename)) DBUG_RETURN(EXIT_UNSPECIFIED_ERROR); @@ -610,7 +652,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, continue; } if ((!option_is_autoset) && - ((error= setval(optp, value, argument, set_maximum_value))) && + ((error= setval(optp, value, argument, set_maximum_value,filename))) && !option_is_loose) DBUG_RETURN(error); if (get_one_option(optp, argument, filename)) @@ -711,7 +753,7 @@ static my_bool get_bool_argument(const struct my_option *opts, */ static int setval(const struct my_option *opts, void *value, char *argument, - my_bool set_maximum_value) + my_bool set_maximum_value, const char *option_file) { int err= 0, res= 0; DBUG_ENTER("setval"); @@ -858,6 +900,7 @@ static int setval(const struct my_option *opts, void *value, char *argument, goto ret; }; } + validate_value(opts->name, argument, option_file); DBUG_RETURN(0); ret: |