--- libaitio/src/Attic/vars.c 2011/11/03 14:17:39 1.2.2.1 +++ libaitio/src/Attic/vars.c 2011/11/03 14:56:48 1.2.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: vars.c,v 1.2.2.1 2011/11/03 14:17:39 misho Exp $ +* $Id: vars.c,v 1.2.2.3 2011/11/03 14:56:48 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -47,14 +47,14 @@ SUCH DAMAGE. /* - * io_vals2buffer() Marshaling data from array with variables to buffer + * io_vars2buffer() Marshaling data from array with variables to buffer * @buf = Buffer * @buflen = Size of buffer * @vars = Variable array * return: -1 error, 0 nothing done or >0 size of marshaled data */ int -io_vals2buffer(u_char *buf, int buflen, array_t *vars) +io_vars2buffer(u_char *buf, int buflen, array_t *vars) { int Limit = 0; register int i; @@ -126,7 +126,7 @@ io_vals2buffer(u_char *buf, int buflen, array_t *vars) } /* - * io_buffer2vals() De-marshaling data from buffer to array with variables + * io_buffer2vars() De-marshaling data from buffer to array with variables * @buf = Buffer * @buflen = Size of buffer * @vnum = Number of variables into buffer @@ -135,7 +135,7 @@ io_vals2buffer(u_char *buf, int buflen, array_t *vars) * return: =NULL error, !=NULL allocated variable array, after use must free with io_arrayDestroy() */ array_t * -io_buffer2vals(u_char *buf, int buflen, int vnum, int zcpy) +io_buffer2vars(u_char *buf, int buflen, int vnum, int zcpy) { array_t *vars; int Limit = 0; @@ -240,14 +240,14 @@ io_buffer2vals(u_char *buf, int buflen, int vnum, int /* buffer marshaling without swapping bytes to network order */ /* - * io_vals2map() Marshaling data from array with variables to memory map + * io_vars2map() Marshaling data from array with variables to memory map * @buf = Buffer * @buflen = Size of buffer * @vars = Variable array * return: -1 error, 0 nothing done or >0 size of marshaled data */ int -io_vals2map(u_char *buf, int buflen, array_t *vars) +io_vars2map(u_char *buf, int buflen, array_t *vars) { int Limit = 0; register int i; @@ -319,7 +319,7 @@ io_vals2map(u_char *buf, int buflen, array_t *vars) } /* - * io_map2vals() De-marshaling data from memory map to array with variables + * io_map2vars() De-marshaling data from memory map to array with variables * @buf = Buffer * @buflen = Size of buffer * @vnum = Number of variables into buffer @@ -328,7 +328,7 @@ io_vals2map(u_char *buf, int buflen, array_t *vars) * return: =NULL error, !=NULL allocated variable array, after use must free with io_arrayDestroy() */ array_t * -io_map2vals(u_char *buf, int buflen, int vnum, int zcpy) +io_map2vars(u_char *buf, int buflen, int vnum, int zcpy) { array_t *vars; int Limit = 0; @@ -454,6 +454,23 @@ io_allocVars(u_int varnum) } /* + * io_clrVars() Clear ait_val_t elements from array + * @vars = Variable array + * return: none + */ +inline int +io_clrVars(array_t * __restrict vars) +{ + register int i; + + for (i = 0; i < io_arraySize(vars); i++) + if (io_arrayGet(vars, i)) + AIT_FREE_VAL(io_array(vars, i, ait_val_t*)); + + return io_arraySize(vars); +} + +/* * io_freeVars() Free ait_val_t array * @vars = Variable array * return: none @@ -461,15 +478,10 @@ io_allocVars(u_int varnum) inline void io_freeVars(array_t ** __restrict vars) { - register int i; - if (!vars || !*vars) return; - for (i = 0; i < io_arraySize(*vars); i++) - if (io_arrayGet(*vars, i)) - AIT_FREE_VAL(io_array(*vars, i, ait_val_t*)); - + io_clrVars(*vars); io_arrayFree(*vars); io_arrayDestroy(vars); }