--- libaitcfg/src/aitcfg.c 2023/01/23 23:27:26 1.16 +++ libaitcfg/src/aitcfg.c 2025/08/19 11:40:13 1.16.6.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcfg.c,v 1.16 2023/01/23 23:27:26 misho Exp $ +* $Id: aitcfg.c,v 1.16.6.4 2025/08/19 11:40:13 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 - 2023 +Copyright 2004 - 2025 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -157,6 +157,29 @@ cfgEndConfig(cfg_root_t **pcfg) } /* + * cfgInitConfigExt() - Init existed config root + * + * @cfg = Config root + * return: -1 error or 0 inited config root + */ +int +cfgInitConfigExt(cfg_root_t * __restrict cfg) +{ + if (!cfg) { + cfg_SetErr(EINVAL, "Invalid parameter"); + return -1; + } + + memset(cfg, 0, sizeof(cfg_root_t)); + + pthread_mutex_init(&cfg->rc_mtx, NULL); + + TAILQ_INIT(cfg); + RB_INIT(cfg); + return 0; +} + +/* * cfgLoadConfig() - Load config from file * * @cfgName = Config filename @@ -169,16 +192,9 @@ cfgLoadConfig(const char *cfgName, cfg_root_t * __rest FILE *f; int ret; - if (!cfgName || !cfg) { + if (!cfgName || cfgInitConfigExt(cfg)) { cfg_SetErr(EINVAL, "Invalid parameter(s)"); return -1; - } else { - memset(cfg, 0, sizeof(cfg_root_t)); - - pthread_mutex_init(&cfg->rc_mtx, NULL); - - TAILQ_INIT(cfg); - RB_INIT(cfg); } f = fopen(cfgName, "r"); @@ -234,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); } /*