mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-05 04:06:34 -05:00
ucm: Include directive - add optional behaviour
It may be useful to skip the include when the file does not exist (make it optional). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
22f8716af9
commit
ae921dc1c9
1 changed files with 21 additions and 1 deletions
|
|
@ -43,7 +43,9 @@ static int include_eval_one(snd_use_case_mgr_t *uc_mgr,
|
|||
snd_config_t **before,
|
||||
snd_config_t **after)
|
||||
{
|
||||
snd_config_t *opt;
|
||||
const char *file;
|
||||
bool opt_bool = false;
|
||||
char *s;
|
||||
int err;
|
||||
|
||||
|
|
@ -72,10 +74,28 @@ static int include_eval_one(snd_use_case_mgr_t *uc_mgr,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = snd_config_search(inc, "Optional", &opt);
|
||||
if (err < 0 && err != -ENOENT) {
|
||||
snd_error(UCM, "optional error");
|
||||
return -EINVAL;
|
||||
} else if (err == 0) {
|
||||
err = snd_config_get_bool(opt);
|
||||
if (err < 0) {
|
||||
snd_error(UCM, "optional format error");
|
||||
return -EINVAL;
|
||||
}
|
||||
opt_bool = err > 0;
|
||||
}
|
||||
|
||||
err = uc_mgr_get_substituted_value(uc_mgr, &s, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = uc_mgr_config_load_file(uc_mgr, s, result);
|
||||
if (opt_bool && access(s, R_OK) != 0) {
|
||||
snd_trace(UCM, "optional file '%s' not found", s);
|
||||
err = 0;
|
||||
} else {
|
||||
err = uc_mgr_config_load_file(uc_mgr, s, result);
|
||||
}
|
||||
free(s);
|
||||
return err;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue