--- libaitcfg/src/aitcfg.c 2012/04/03 09:21:06 1.4.4.2 +++ libaitcfg/src/aitcfg.c 2012/07/25 15:24:20 1.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcfg.c,v 1.4.4.2 2012/04/03 09:21:06 misho Exp $ +* $Id: aitcfg.c,v 1.7 2012/07/25 15:24:20 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -115,9 +115,8 @@ cfgInitConfig(cfg_root_t * __restrict cfg) if (!cfg) return -1; -#ifdef HAVE_LIBPTHREAD pthread_mutex_init(&cfg->rc_mtx, NULL); -#endif + SLIST_INIT(cfg); RB_INIT(cfg); return 0; @@ -155,13 +154,13 @@ cfgLoadConfig(const char *cfgName, cfg_root_t * __rest } /* - * cfgUnloadConfig() - Unload config from memory and free resources + * cfgClearConfig() - Clear config and free resources * * @cfg = Config root * return: none */ void -cfgUnloadConfig(cfg_root_t * __restrict cfg) +cfgClearConfig(cfg_root_t * __restrict cfg) { struct tagCfg *av; @@ -175,51 +174,38 @@ cfgUnloadConfig(cfg_root_t * __restrict cfg) AIT_FREE_VAL(&av->cfg_val); AIT_FREE_VAL(&av->cfg_attr); AIT_FREE_VAL(&av->cfg_sec); - free(av); + io_free(av); } cfg->rbh_root = NULL; CFG_RC_UNLOCK(cfg); - -#ifdef HAVE_LIBPTHREAD - pthread_mutex_destroy(&cfg->rc_mtx); -#endif } -#if 0 /* - * CreateConfig() Create config file from memory - * @csConfigName = New config filename - * @cfg = Head list element - * return: 0 ok; -1 error:: can`t save new config -*/ -int CreateConfig(const char *csConfigName, sl_config * __restrict cfg) + * cfgUnloadConfig() - Unload config from memory and destroy resources + * + * @cfg = Config root + * return: none + */ +void +cfgUnloadConfig(cfg_root_t * __restrict cfg) { - FILE *f; - int ret; + if (!cfg) + return; - if (!csConfigName || !cfg) - return -1; - - f = fopen(csConfigName, "wt"); - if (!f) { - LOGERR; - return -1; - } - - ret ^= ret; - ret = WriteConfig(f, cfg); - - fclose(f); - return ret; + cfgClearConfig(cfg); + pthread_mutex_destroy(&cfg->rc_mtx); } /* - * cfg_CreateConfig() Create config file from memory without whitespaces! + * cfgCreateConfig() - Create config file from memory + * * @csConfigName = New config filename - * @cfg = Head list element - * return: 0 ok; -1 error:: can`t save new config -*/ -int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg) + * @cfg = Config root + * @whitespace = Additional whitespace characters to file + * return: -1 error or 0 ok + */ +int +cfgCreateConfig(const char *csConfigName, cfg_root_t * __restrict cfg, int whitespace) { FILE *f; int ret; @@ -227,16 +213,14 @@ int cfg_CreateConfig(const char *csConfigName, sl_conf if (!csConfigName || !cfg) return -1; - f = fopen(csConfigName, "wt"); + f = fopen(csConfigName, "w"); if (!f) { LOGERR; return -1; } - ret ^= ret; - ret = cfg_WriteConfig(f, cfg); + ret = cfgWriteConfig(f, cfg, whitespace); fclose(f); return ret; } -#endif