--- libaitcfg/src/aitcfg.c 2021/11/25 23:44:52 1.14.2.1 +++ libaitcfg/src/aitcfg.c 2025/08/19 10:42:28 1.16.6.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcfg.c,v 1.14.2.1 2021/11/25 23:44:52 misho Exp $ +* $Id: aitcfg.c,v 1.16.6.1 2025/08/19 10:42:28 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2021 +Copyright 2004 - 2025 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -157,6 +157,27 @@ cfgEndConfig(cfg_root_t **pcfg) } /* + * cfgInitConfigExt() - Init existed config root + * + * @cfg = Config root + * return: NULL error or !=NULL inited config root + */ +cfg_root_t * +cfgInitConfigExt(cfg_root_t * __restrict cfg) +{ + if (!TAILQ_EMPTY(cfg) || !RB_EMPTY(cfg)) + cfgUnloadConfig(cfg); + + memset(cfg, 0, sizeof(cfg_root_t)); + + pthread_mutex_init(&cfg->rc_mtx, NULL); + + TAILQ_INIT(cfg); + RB_INIT(cfg); + return cfg; +} + +/* * cfgLoadConfig() - Load config from file * * @cfgName = Config filename @@ -173,6 +194,9 @@ cfgLoadConfig(const char *cfgName, cfg_root_t * __rest cfg_SetErr(EINVAL, "Invalid parameter(s)"); return -1; } else { + if (!TAILQ_EMPTY(cfg) || !RB_EMPTY(cfg)) + cfgUnloadConfig(cfg); + memset(cfg, 0, sizeof(cfg_root_t)); pthread_mutex_init(&cfg->rc_mtx, NULL); @@ -259,7 +283,7 @@ cfgCreateConfig(const char *csConfigName, cfg_root_t * return -1; } - ret = cfgWriteConfig(f, cfg, whitespace); + ret = cfgWriteConfigRaw(f, cfg, whitespace); fclose(f); return ret;