--- libaitcfg/src/parse.c 2012/09/17 14:17:12 1.10.2.4 +++ libaitcfg/src/parse.c 2012/09/18 13:24:50 1.10.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: parse.c,v 1.10.2.4 2012/09/17 14:17:12 misho Exp $ +* $Id: parse.c,v 1.10.2.5 2012/09/18 13:24:50 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -47,19 +47,6 @@ SUCH DAMAGE. #include "aitcfg.h" -static inline int -cfg_Write(FILE *f, char *fmt, ...) -{ - int ret = 0; - va_list lst; - - va_start(lst, fmt); - ret = vfprintf(f, fmt, lst); - va_end(lst); - - return ret; -} - static inline void _invertQueue(cfg_root_t * __restrict cfg) { @@ -88,6 +75,11 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) int flg = 0; char *psAttr, *psVal, szSection[STRSIZ] = { 0 }; + if (!f || !cfg) { + cfg_SetErr(EINVAL, "Invalid parameter(s)"); + return -1; + } + while (!feof(f)) { memset(line, 0, sizeof line); fgets(line, sizeof line - 1, f); @@ -124,7 +116,7 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) /* *NEW PAIR* alloc new pair element */ av = io_malloc(sizeof(struct tagCfg)); if (!av) { - LOGERR; + cfg_SetErr(io_GetErrno(), "%s", io_GetError()); return -1; } else { memset(av, 0, sizeof(struct tagCfg)); @@ -207,6 +199,11 @@ cfgWriteConfig(FILE *f, cfg_root_t * __restrict cfg, i time_t tim; char line[BUFSIZ] = { 0 }, szSection[STRSIZ] = { 0 }; + if (!f || !cfg) { + cfg_SetErr(EINVAL, "Invalid parameter(s)"); + return -1; + } + CFG_RC_LOCK(cfg); _invertQueue(cfg); SLIST_FOREACH(av, cfg, cfg_next) { @@ -244,6 +241,7 @@ cfgWriteConfig(FILE *f, cfg_root_t * __restrict cfg, i /* write */ if (!cfg_Write(f, "%s\n", line)) { LOGERR; + _invertQueue(cfg); CFG_RC_UNLOCK(cfg); return -1; }