--- libaitio/src/Attic/vars.c 2012/08/29 13:49:04 1.12.4.3 +++ libaitio/src/Attic/vars.c 2012/09/03 09:26:34 1.13.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: vars.c,v 1.12.4.3 2012/08/29 13:49:04 misho Exp $ +* $Id: vars.c,v 1.13.2.1 2012/09/03 09:26:34 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -746,3 +746,35 @@ io_findKeyHash(array_t * __restrict vars, const char * return io_findKeyVars(vars, k); } +/* + * io_sprintfVar() - Builtin string variable from formatted input + * + * @v = variable + * @fmt = format string + * @... = argument(s) + * return: -1 error or >0 copied bytes to variable + */ +int +io_sprintfVar(ait_val_t * __restrict v, const char *fmt, ...) +{ + int ret = 0; + va_list lst; + char *str = NULL; + + if (!v || !fmt) + return -1; + + va_start(lst, fmt); + ret = vasprintf(&str, fmt, lst); + va_end(lst); + + if (str && ret > -1) { + AIT_FREE_VAL(v); + AIT_SET_STR(v, str); + } else + LOGERR; + + if (str) + free(str); + return ret; +}