--- libaitcfg/src/aitcfg.c 2008/09/30 14:52:17 1.1.1.1.2.1 +++ libaitcfg/src/aitcfg.c 2009/09/09 10:44:41 1.2.2.1 @@ -1,3 +1,11 @@ +/************************************************************************* +* (C) 2008 AITNET ltd - Sofia/Bulgaria - +* by Michael Pounov +* +* $Author: misho $ +* $Id: aitcfg.c,v 1.2.2.1 2009/09/09 10:44:41 misho Exp $ +* +*************************************************************************/ #include "global.h" #include "aitcfg.h" @@ -68,7 +76,7 @@ void UnloadConfig(sl_config * __restrict cfg) if (!cfg->slh_first) return; - for (av = cfg->slh_first; av; av = av->sle_next) { + while ((av = cfg->slh_first)) { cfg->slh_first = cfg->slh_first->sle_next; if (av->psValue) @@ -103,6 +111,33 @@ int CreateConfig(const char *csConfigName, sl_config * ret ^= ret; ret = WriteConfig(f, cfg); + + fclose(f); + return ret; +} + +/* + * cfg_CreateConfig() Create config file from memory without whitespaces! + * @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) +{ + FILE *f; + int ret; + + if (!csConfigName || !cfg) + return -1; + + f = fopen(csConfigName, "wt"); + if (!f) { + LOGERR; + return -1; + } + + ret ^= ret; + ret = cfg_WriteConfig(f, cfg); fclose(f); return ret;