--- libaitio/inc/aitio.h 2012/05/14 12:49:21 1.17 +++ libaitio/inc/aitio.h 2012/05/15 13:39:08 1.17.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.h,v 1.17 2012/05/14 12:49:21 misho Exp $ +* $Id: aitio.h,v 1.17.4.2 2012/05/15 13:39:08 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -153,13 +153,27 @@ typedef struct { #define AIT_SET_PTR(_vl, _p, _len) do { ait_val_t *__val = (_vl); assert(__val); \ __val->val_type = ptr; AIT_LEN(__val) = _len; \ __val->val.ptr = _p; } while (0) +#define AIT_RE_BUF(_vl, _len) do { ait_val_t *__val = (_vl); assert(__val); \ + void *__ptr = realloc(AIT_GET_BUF(__val), _len); \ + if (__ptr) { \ + __val->val.buffer = __ptr; AIT_LEN(__val) = _len; \ + } } while (0) +#define AIT_SET_BUF2(_vl, _c, _len) do { ait_val_t *__val = (_vl); assert(__val); \ + __val->val.buffer = malloc(_len); \ + if (__val->val.buffer) { \ + __val->val_type = buffer; AIT_LEN(__val) = _len; \ + memset(__val->val.buffer, _c, _len); \ + } } while (0) #define AIT_SET_BUF(_vl, _v, _len) do { ait_val_t *__val = (_vl); assert(__val); \ __val->val.buffer = malloc(_len); \ if (__val->val.buffer) { \ __val->val_type = buffer; AIT_LEN(__val) = _len; \ - memcpy(__val->val.buffer, (_v), _len); \ + if ((_v)) \ + memcpy(__val->val.buffer, (_v), _len); \ + else \ + memset(__val->val.buffer, 0, _len); \ } } while (0) -#define AIT_SET_STR(_vl, _v) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_STR(_vl, _v) do { ait_val_t *__val = (_vl); assert(__val && (_v)); \ __val->val.string = (int8_t*) strdup((_v)); \ if (__val->val.string) { \ __val->val_type = string; \