summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-30 21:24:48 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-30 21:45:06 -0700
commit4d66819a175b1b24d9ece3264b4b2f7a6bfab9d1 (patch)
treeddf25e3a539e7f7a76886dd2ba0e707d9d022a40
parent5bbf4dff64f2b559540f47a9d8de99353004dce4 (diff)
til_setup: add helper for setup_func baking fails
This introduces til_setup_free_with_failed_setting_ret_err() which just does the common idiom of: - free the setup - store the failed setting - return with err code so all these failure cases can be reduced to just a direct return of calling this function.
-rw-r--r--src/til_setup.c14
-rw-r--r--src/til_setup.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/src/til_setup.c b/src/til_setup.c
index ce95366..c06614f 100644
--- a/src/til_setup.c
+++ b/src/til_setup.c
@@ -110,3 +110,17 @@ void * til_setup_free(til_setup_t *setup)
return NULL;
}
+
+
+/* ergonomic helper for setup_funcs to use in res_setup baking */
+int til_setup_free_with_failed_setting_ret_err(til_setup_t *setup, til_setting_t *failed_setting, til_setting_t **res_setting, int err)
+{
+ assert(failed_setting);
+ assert(res_setting);
+ assert(err < 0);
+
+ til_setup_free(setup);
+ *res_setting = failed_setting;
+
+ return err;
+}
diff --git a/src/til_setup.h b/src/til_setup.h
index 905dd6e..eac1444 100644
--- a/src/til_setup.h
+++ b/src/til_setup.h
@@ -4,6 +4,7 @@
#include <stdint.h>
typedef struct til_settings_t til_settings_t;
+typedef struct til_setting_t til_setting_t;
typedef struct til_setup_t til_setup_t;
struct til_setup_t {
@@ -17,5 +18,6 @@ struct til_setup_t {
void * til_setup_new(const til_settings_t *settings, size_t size, void (*free_func)(til_setup_t *setup), const void *creator);
void * til_setup_ref(til_setup_t *setup);
void * til_setup_free(til_setup_t *setup);
+int til_setup_free_with_failed_setting_ret_err(til_setup_t *setup, til_setting_t *failed_setting, til_setting_t **res_setting, int err);
#endif
© All Rights Reserved