From: Michael Tremer Date: Wed, 1 Feb 2023 21:46:11 +0000 (+0000) Subject: networkd: config: Split flushing all entries into a function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91915f80f60943afec29743eda7258f5bf65e8e5;p=network.git networkd: config: Split flushing all entries into a function Signed-off-by: Michael Tremer --- diff --git a/src/networkd/config.c b/src/networkd/config.c index b2a23f00..a11ee1cc 100644 --- a/src/networkd/config.c +++ b/src/networkd/config.c @@ -74,15 +74,8 @@ ERROR: } static void nw_config_free(struct nw_config* config) { - struct nw_config_entry* entry = NULL; - - while (!STAILQ_EMPTY(&config->entries)) { - entry = STAILQ_FIRST(&config->entries); - STAILQ_REMOVE_HEAD(&config->entries, nodes); - - // Free the entry - nw_config_entry_free(entry); - } + // Flush all entries + nw_config_flush(config); free(config); } @@ -117,6 +110,20 @@ struct nw_config* nw_config_unref(struct nw_config* config) { return NULL; } +int nw_config_flush(struct nw_config* config) { + struct nw_config_entry* entry = NULL; + + while (!STAILQ_EMPTY(&config->entries)) { + entry = STAILQ_FIRST(&config->entries); + STAILQ_REMOVE_HEAD(&config->entries, nodes); + + // Free the entry + nw_config_entry_free(entry); + } + + return 0; +} + static int nw_config_parse(struct nw_config* config, FILE* f) { // XXX TODO diff --git a/src/networkd/config.h b/src/networkd/config.h index 3474ae13..38780631 100644 --- a/src/networkd/config.h +++ b/src/networkd/config.h @@ -33,6 +33,8 @@ int nw_config_create(struct nw_config** config); struct nw_config* nw_config_ref(struct nw_config* config); struct nw_config* nw_config_unref(struct nw_config* config); +int nw_config_flush(struct nw_config* config); + int nw_config_readf(struct nw_config** config, FILE* f); int nw_config_read(struct nw_config** config, const char* path);