summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-10 23:16:22 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-10 23:16:22 -0400
commit39d7cea180c3571d79d74d4efcd0efd9f820b53a (patch)
tree74c4c15b5b2ab430f598c19d21b224e6c4728071 /config.c
parentec34e9ce8a380df87dbf5b455b62e805c00ca8d3 (diff)
Added the `cleanup()`, and `cleanup_config()`
functions.
Diffstat (limited to 'config.c')
-rw-r--r--config.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/config.c b/config.c
index f0622c5..8f5722b 100644
--- a/config.c
+++ b/config.c
@@ -105,6 +105,17 @@ void set_config_opt(config *conf, config_type type, size_t offset, config_val va
}
}
+void cleanup_config(config *conf) {
+ char *cfg = (char *)conf;
+ for (const config_opt *opt = config_opts; opt->name != NULL; opt++) {
+ /* Is this config option's type a string, and is the string of that config option in conf not NULL? */
+ if (opt->type == TYPE_STRING && *(char **)(cfg+opt->offset) != NULL) {
+ free(*(char **)(cfg+opt->offset));
+ }
+ }
+ free(conf);
+}
+
config *parse_config(const char *filename) {
/* Size of the file, in bytes. */
long filesize = 0;