--- libaitcfg/src/aitcfg.c 2025/08/19 11:06:32 1.16.6.2 +++ libaitcfg/src/aitcfg.c 2025/08/19 11:43:53 1.17 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcfg.c,v 1.16.6.2 2025/08/19 11:06:32 misho Exp $ +* $Id: aitcfg.c,v 1.17 2025/08/19 11:43:53 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -160,24 +160,23 @@ cfgEndConfig(cfg_root_t **pcfg) * cfgInitConfigExt() - Init existed config root * * @cfg = Config root - * return: NULL error or !=NULL inited config root + * return: -1 error or 0 inited config root */ -cfg_root_t * +int cfgInitConfigExt(cfg_root_t * __restrict cfg) { - pthread_mutex_t mtx = { 0 }; + if (!cfg) { + cfg_SetErr(EINVAL, "Invalid parameter"); + return -1; + } - if (!TAILQ_EMPTY(cfg) || !RB_EMPTY(cfg) || - memcmp(&cfg->rc_mtx, &mtx, sizeof mtx)) - cfgUnloadConfig(cfg); - memset(cfg, 0, sizeof(cfg_root_t)); pthread_mutex_init(&cfg->rc_mtx, NULL); TAILQ_INIT(cfg); RB_INIT(cfg); - return cfg; + return 0; } /* @@ -192,22 +191,10 @@ cfgLoadConfig(const char *cfgName, cfg_root_t * __rest { FILE *f; int ret; - pthread_mutex_t mtx = { 0 }; - if (!cfgName || !cfg) { + if (!cfgName || cfgInitConfigExt(cfg)) { cfg_SetErr(EINVAL, "Invalid parameter(s)"); return -1; - } else { - if (!TAILQ_EMPTY(cfg) || !RB_EMPTY(cfg) || - memcmp(&cfg->rc_mtx, &mtx, sizeof mtx)) - cfgUnloadConfig(cfg); - - memset(cfg, 0, sizeof(cfg_root_t)); - - pthread_mutex_init(&cfg->rc_mtx, NULL); - - TAILQ_INIT(cfg); - RB_INIT(cfg); } f = fopen(cfgName, "r"); @@ -263,6 +250,7 @@ cfgUnloadConfig(cfg_root_t * __restrict cfg) cfgClearConfig(cfg); pthread_mutex_destroy(&cfg->rc_mtx); + memset(&cfg->rc_mtx, 0, sizeof cfg->rc_mtx); } /*