mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
qemu-option: has_help_option() and is_valid_option_list()
has_help_option() checks if any help option ('help' or '?') occurs anywhere in an option string, so that things like 'cluster_size=4k,help' are recognised. is_valid_option_list() ensures that the option list doesn't have options with leading commas or trailing unescaped commas. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
5b7aa9b56d
commit
7cc07ab8da
2 changed files with 51 additions and 0 deletions
|
@ -450,6 +450,55 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool has_help_option(const char *param)
|
||||
{
|
||||
size_t buflen = strlen(param) + 1;
|
||||
char *buf = g_malloc0(buflen);
|
||||
const char *p = param;
|
||||
bool result = false;
|
||||
|
||||
while (*p) {
|
||||
p = get_opt_value(buf, buflen, p);
|
||||
if (*p) {
|
||||
p++;
|
||||
}
|
||||
|
||||
if (is_help_option(buf)) {
|
||||
result = true;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_valid_option_list(const char *param)
|
||||
{
|
||||
size_t buflen = strlen(param) + 1;
|
||||
char *buf = g_malloc0(buflen);
|
||||
const char *p = param;
|
||||
bool result = true;
|
||||
|
||||
while (*p) {
|
||||
p = get_opt_value(buf, buflen, p);
|
||||
if (*p && !*++p) {
|
||||
result = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!*buf || *buf == ',') {
|
||||
result = false;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints all options of a list that have a value to stdout
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue