diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-04-22 12:42:01 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-04-22 12:42:01 -0700 |
commit | 0a798f421863d7c74bf7e8e6f37d8021e9df52f2 (patch) | |
tree | f84a4a3719678a44558a3504a8f8892b9b52c79d /src/til.c | |
parent | 7f872664738b45c982f3e95749f2136a0de4c19a (diff) |
til: make til_module_randomize_setup() return -errno
This makes the arg return optional by using a res_arg pointer,
instead returning -ENOMEM when it would have returned NULL on
allocation failures.
This also makes it possible to detect when no setup was
performed, by returning 0 in such a case. Now returns 1 when
setup occurs and res pointers populated.
Diffstat (limited to 'src/til.c')
-rw-r--r-- | src/til.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -236,22 +236,24 @@ int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, cons } -/* originally taken from rtv, this randomizes a module's setup @res_setup, returning args form as well */ -char * til_module_randomize_setup(const til_module_t *module, void **res_setup) +/* originally taken from rtv, this randomizes a module's setup @res_setup, args @res_arg + * returns 0 on no setup, 1 on setup successful with results stored @res_*, -errno on error. + */ +int til_module_randomize_setup(const til_module_t *module, void **res_setup, char **res_arg) { til_settings_t *settings; til_setting_t *setting; const til_setting_desc_t *desc; - char *arg; + int r = 1; assert(module); if (!module->setup) - return NULL; + return 0; settings = til_settings_new(NULL); if (!settings) - return NULL; + return -ENOMEM; while (module->setup(settings, &setting, &desc, res_setup) > 0) { if (desc->random) { @@ -273,8 +275,17 @@ char * til_module_randomize_setup(const til_module_t *module, void **res_setup) } } - arg = til_settings_as_arg(settings); + if (res_arg) { + char *arg; + + arg = til_settings_as_arg(settings); + if (!arg) + r = -ENOMEM; + else + *res_arg = arg; + } + til_settings_free(settings); - return arg; + return r; } |