version 1.1.1.1, 2013/01/17 10:05:35
|
version 1.10, 2022/01/24 17:08:21
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 | Copyright 2004 - 2022 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 46 SUCH DAMAGE.
|
Line 46 SUCH DAMAGE.
|
#include "global.h" |
#include "global.h" |
|
|
|
|
static int | static inline int |
vars2buffer(u_char * __restrict buf, int buflen, int be, array_t * __restrict vars) |
vars2buffer(u_char * __restrict buf, int buflen, int be, array_t * __restrict vars) |
{ |
{ |
int Limit = 0; |
int Limit = 0; |
Line 123 vars2buffer(u_char * __restrict buf, int buflen, int b
|
Line 123 vars2buffer(u_char * __restrict buf, int buflen, int b
|
break; |
break; |
case buffer: |
case buffer: |
case string: |
case string: |
|
case ptr: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
elwix_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
elwix_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
"needed min %d", buflen, Limit + AIT_LEN(val)); |
"needed min %d", buflen, Limit + AIT_LEN(val)); |
Line 145 vars2buffer(u_char * __restrict buf, int buflen, int b
|
Line 146 vars2buffer(u_char * __restrict buf, int buflen, int b
|
return Limit; |
return Limit; |
} |
} |
|
|
static array_t * | static inline array_t * |
buffer2vars(u_char * __restrict buf, int buflen, int vnum, int zcpy) |
buffer2vars(u_char * __restrict buf, int buflen, int vnum, int zcpy) |
{ |
{ |
array_t *vars; |
array_t *vars; |
Line 218 buffer2vars(u_char * __restrict buf, int buflen, int v
|
Line 219 buffer2vars(u_char * __restrict buf, int buflen, int v
|
val->val.net = le64toh(v[i].val.net); |
val->val.net = le64toh(v[i].val.net); |
break; |
break; |
case data: |
case data: |
/* WARNING:: remap data type to buffer */ | case ptr: |
| /* WARNING:: remap data and ptr type to buffer! */ |
val->val_type = buffer; |
val->val_type = buffer; |
case buffer: |
case buffer: |
case string: |
case string: |
if (AIT_LEN(val) > buflen - Limit) { |
|
elwix_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
|
"needed min %d", buflen, Limit + AIT_LEN(val)); |
|
if (!zcpy) |
|
array_Free(vars); |
|
array_Destroy(&vars); |
|
return NULL; |
|
} else |
|
Limit += AIT_LEN(val); |
|
|
|
if (!zcpy) { |
if (!zcpy) { |
val->val.buffer = e_malloc(AIT_LEN(val)); |
val->val.buffer = e_malloc(AIT_LEN(val)); |
if (!val->val.buffer) { |
if (!val->val.buffer) { |
Line 257 buffer2vars(u_char * __restrict buf, int buflen, int v
|
Line 249 buffer2vars(u_char * __restrict buf, int buflen, int v
|
return vars; |
return vars; |
} |
} |
|
|
|
/* |
|
* ait_vars2tlv() - Marshaling data from array with variables to TLV buffer |
|
* |
|
* @buf = Buffer, If =NULL then we return only needed buffer size |
|
* @buflen = Size of buffer |
|
* @vars = Variable array |
|
* return: -1 error, 0 nothing done or >0 size of marshaled data |
|
*/ |
|
int |
|
ait_vars2tlv(u_char * __restrict buf, int buflen, array_t * __restrict vars) |
|
{ |
|
int Limit = 0; |
|
register int i; |
|
ait_val_t *val; |
|
u_char *dat; |
|
|
|
assert(vars); |
|
if (!vars) |
|
return -1; |
|
if (!array_Size(vars)) |
|
return 0; |
|
|
|
/* calculate amount of data into buffer */ |
|
for (i = 0, Limit = 0; i < array_Size(vars); |
|
Limit += 5 + AIT_LEN(array(vars, i, ait_val_t*)), i++); |
|
/* check only needed buffer size */ |
|
if (!buf) |
|
return Limit; |
|
|
|
if (Limit > buflen) { |
|
elwix_SetErr(EMSGSIZE, "Short buffer buflen=%d needed min %d", |
|
buflen, Limit); |
|
return -1; |
|
} else |
|
memset(buf, 0, buflen); |
|
|
|
/* marshaling */ |
|
for (i = 0, dat = buf; i < array_Size(vars) && dat < (buf + Limit); i++) { |
|
val = array(vars, i, ait_val_t*); |
|
|
|
*dat++ = AIT_TYPE(val); |
|
|
|
*((uint32_t*) dat) = htonl(AIT_LEN(val)); |
|
dat += sizeof(uint32_t); |
|
|
|
switch (AIT_TYPE(val)) { |
|
case i8: |
|
*((int8_t*) dat) = AIT_GET_I8(val); |
|
break; |
|
case u8: |
|
*((uint8_t*) dat) = AIT_GET_U8(val); |
|
break; |
|
case i16: |
|
*((int16_t*) dat) = AIT_GET_I16(val); |
|
break; |
|
case u16: |
|
*((uint16_t*) dat) = AIT_GET_U16(val); |
|
break; |
|
case i32: |
|
*((int32_t*) dat) = AIT_GET_I32(val); |
|
break; |
|
case blob: |
|
case u32: |
|
*((uint32_t*) dat) = AIT_GET_U32(val); |
|
break; |
|
case i64: |
|
*((int64_t*) dat) = AIT_GET_I64(val); |
|
break; |
|
case u64: |
|
*((uint64_t*) dat) = AIT_GET_U64(val); |
|
break; |
|
case f32: |
|
*((float*) dat) = AIT_GET_F32(val); |
|
break; |
|
case f64: |
|
*((double*) dat) = AIT_GET_F64(val); |
|
break; |
|
case data: |
|
memcpy(dat, AIT_GET_DATA(val), AIT_LEN(val)); |
|
break; |
|
case buffer: |
|
memcpy(dat, AIT_GET_BUF(val), AIT_LEN(val)); |
|
break; |
|
case string: |
|
memcpy(dat, AIT_GET_STR(val), AIT_LEN(val)); |
|
break; |
|
case ptr: |
|
memcpy(dat, AIT_GET_PTR(val), AIT_LEN(val)); |
|
break; |
|
default: |
|
elwix_SetErr(EINVAL, "Unsupported variable type=%d at element #%d", |
|
AIT_TYPE(val), i); |
|
return -1; |
|
} |
|
dat += AIT_LEN(val); |
|
} |
|
|
|
return Limit; |
|
} |
|
|
|
/* |
|
* ait_tlv2vars() - De-marshaling data from TLV buffer to array with variables |
|
* |
|
* @buf = Buffer |
|
* @buflen = Size of buffer |
|
* return: =NULL error, !=NULL allocated variable array, after use must free with ait_freeVars() |
|
*/ |
|
array_t * |
|
ait_tlv2vars(u_char * __restrict buf, int buflen) |
|
{ |
|
array_t *vars; |
|
register int i; |
|
ait_val_t *val; |
|
u_char *dat; |
|
|
|
assert(buf); |
|
if (!buf || !buflen) |
|
return NULL; |
|
|
|
if (!(vars = ait_allocVars(1))) |
|
return NULL; |
|
|
|
/* de-marshaling */ |
|
for (i = 0, dat = buf; *dat != empty && dat < (buf + buflen); i++) { |
|
val = ait_getVars(&vars, i); |
|
if (!val) { |
|
ait_freeVars(&vars); |
|
return NULL; |
|
} |
|
|
|
val->val_type = *dat++; |
|
AIT_LEN(val) = ntohl(*((uint32_t*) dat)); |
|
dat += sizeof(uint32_t); |
|
|
|
switch (AIT_TYPE(val)) { |
|
case f32: |
|
AIT_SET_F32(val, *((float*) dat)); |
|
break; |
|
case f64: |
|
AIT_SET_F64(val, *((double*) dat)); |
|
break; |
|
case i8: |
|
AIT_SET_I8(val, *((int8_t*) dat)); |
|
break; |
|
case i16: |
|
AIT_SET_I16(val, *((int16_t*) dat)); |
|
break; |
|
case i32: |
|
AIT_SET_I32(val, *((int32_t*) dat)); |
|
break; |
|
case i64: |
|
AIT_SET_I64(val, *((int64_t*) dat)); |
|
break; |
|
case u8: |
|
AIT_SET_U8(val, *((uint8_t*) dat)); |
|
break; |
|
case u16: |
|
AIT_SET_U16(val, *((uint16_t*) dat)); |
|
break; |
|
case blob: |
|
case u32: |
|
AIT_SET_U32(val, *((uint32_t*) dat)); |
|
break; |
|
case u64: |
|
AIT_SET_U64(val, *((uint64_t*) dat)); |
|
break; |
|
case data: |
|
AIT_SET_DATA(val, dat, AIT_LEN(val)); |
|
break; |
|
case ptr: |
|
case buffer: |
|
AIT_SET_BUF(val, dat, AIT_LEN(val)); |
|
break; |
|
case string: |
|
AIT_SET_STR(val, (char*) dat); |
|
break; |
|
default: |
|
elwix_SetErr(EINVAL, "Unsupported variable type=%d at element #%d", |
|
AIT_TYPE(val), i); |
|
ait_freeVars(&vars); |
|
return NULL; |
|
} |
|
dat += AIT_LEN(val); |
|
} |
|
|
|
return vars; |
|
} |
|
|
/* buffer marshaling with swapping bytes to network order */ |
/* buffer marshaling with swapping bytes to network order */ |
|
|
/* |
/* |
Line 268 buffer2vars(u_char * __restrict buf, int buflen, int v
|
Line 447 buffer2vars(u_char * __restrict buf, int buflen, int v
|
* @vars = Variable array |
* @vars = Variable array |
* return: -1 error, 0 nothing done or >0 size of marshaled data |
* return: -1 error, 0 nothing done or >0 size of marshaled data |
*/ |
*/ |
inline int | int |
ait_vars2buffer(u_char * __restrict buf, int buflen, array_t * __restrict vars) |
ait_vars2buffer(u_char * __restrict buf, int buflen, array_t * __restrict vars) |
{ |
{ |
return vars2buffer(buf, buflen, 42, vars); |
return vars2buffer(buf, buflen, 42, vars); |
Line 284 ait_vars2buffer(u_char * __restrict buf, int buflen, a
|
Line 463 ait_vars2buffer(u_char * __restrict buf, int buflen, a
|
*DON'T MODIFY OR DESTROY BUFFER*. =0 call array_Free() before array_Destroy() |
*DON'T MODIFY OR DESTROY BUFFER*. =0 call array_Free() before array_Destroy() |
* return: =NULL error, !=NULL allocated variable array, after use must free with array_Destroy() |
* return: =NULL error, !=NULL allocated variable array, after use must free with array_Destroy() |
*/ |
*/ |
inline array_t * | array_t * |
ait_buffer2vars(u_char * __restrict buf, int buflen, int vnum, int zcpy) |
ait_buffer2vars(u_char * __restrict buf, int buflen, int vnum, int zcpy) |
{ |
{ |
return buffer2vars(buf, buflen, vnum, zcpy); |
return buffer2vars(buf, buflen, vnum, zcpy); |
Line 300 ait_buffer2vars(u_char * __restrict buf, int buflen, i
|
Line 479 ait_buffer2vars(u_char * __restrict buf, int buflen, i
|
* @vars = Variable array |
* @vars = Variable array |
* return: -1 error, 0 nothing done or >0 size of marshaled data |
* return: -1 error, 0 nothing done or >0 size of marshaled data |
*/ |
*/ |
inline int | int |
ait_vars2map(u_char *buf, int buflen, array_t *vars) |
ait_vars2map(u_char *buf, int buflen, array_t *vars) |
{ |
{ |
return vars2buffer(buf, buflen, 0, vars); |
return vars2buffer(buf, buflen, 0, vars); |
Line 316 ait_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 495 ait_vars2map(u_char *buf, int buflen, array_t *vars)
|
*DON'T MODIFY OR DESTROY BUFFER*. =0 call array_Free() before array_Destroy() |
*DON'T MODIFY OR DESTROY BUFFER*. =0 call array_Free() before array_Destroy() |
* return: =NULL error, !=NULL allocated variable array, after use must free with array_Destroy() |
* return: =NULL error, !=NULL allocated variable array, after use must free with array_Destroy() |
*/ |
*/ |
inline array_t * | array_t * |
ait_map2vars(u_char *buf, int buflen, int vnum, int zcpy) |
ait_map2vars(u_char *buf, int buflen, int vnum, int zcpy) |
{ |
{ |
return buffer2vars(buf, buflen, vnum, zcpy); |
return buffer2vars(buf, buflen, vnum, zcpy); |
} |
} |
|
|
|
/* |
|
* ait_array2vars() - Build array with variables from Null Terminated String Array |
|
* |
|
* @args = Null-terminated array with strings |
|
* @dn = Convert numbers from strings to numbers into variables |
|
* return: =NULL error, !=NULL allocated variable array, after use must free with ait_freeVars() |
|
*/ |
|
array_t * |
|
ait_array2vars(const char **args, int dn) |
|
{ |
|
array_t *vars; |
|
ait_val_t *val; |
|
register int i; |
|
long n; |
|
float f; |
|
double d; |
|
char *str; |
|
|
|
if (!args) |
|
return NULL; |
|
|
|
vars = ait_allocVars(0); |
|
if (!vars) |
|
return NULL; |
|
|
|
for (i = 0; *args; i++, args++) { |
|
val = ait_getVars(&vars, i); |
|
if (!val) { |
|
ait_freeVars(&vars); |
|
return NULL; |
|
} |
|
|
|
if (dn) { |
|
n = strtol(*args, &str, 0); |
|
if (!str || !*str) { |
|
AIT_SET_I64(val, (int64_t) n); |
|
continue; |
|
} |
|
f = strtof(*args, &str); |
|
if (!str || !*str) { |
|
AIT_SET_F32(val, f); |
|
continue; |
|
} |
|
d = strtod(*args, &str); |
|
if (!str || !*str) { |
|
AIT_SET_F64(val, d); |
|
continue; |
|
} |
|
AIT_SET_STR(val, *args); |
|
} else |
|
AIT_SET_STR(val, *args); |
|
} |
|
|
|
return vars; |
|
} |
|
|
/* variables array */ |
/* variables array */ |
|
|
/* |
/* |
Line 331 ait_map2vars(u_char *buf, int buflen, int vnum, int zc
|
Line 565 ait_map2vars(u_char *buf, int buflen, int vnum, int zc
|
* @varnum = Number of variables |
* @varnum = Number of variables |
* return: =NULL error or !=NULL allocated array |
* return: =NULL error or !=NULL allocated array |
*/ |
*/ |
inline array_t * | array_t * |
ait_allocVars(int varnum) |
ait_allocVars(int varnum) |
{ |
{ |
array_t *arr; |
array_t *arr; |
Line 359 ait_allocVars(int varnum)
|
Line 593 ait_allocVars(int varnum)
|
* @n = index of variable into array |
* @n = index of variable into array |
* return: NULL error or !=NULL ait_val_t element |
* return: NULL error or !=NULL ait_val_t element |
*/ |
*/ |
inline ait_val_t * | ait_val_t * |
ait_getVars(array_t ** __restrict vars, int n) |
ait_getVars(array_t ** __restrict vars, int n) |
{ |
{ |
register int i; |
register int i; |
Line 392 ait_getVars(array_t ** __restrict vars, int n)
|
Line 626 ait_getVars(array_t ** __restrict vars, int n)
|
* @vars = Variable array |
* @vars = Variable array |
* return: -1 error or size of array |
* return: -1 error or size of array |
*/ |
*/ |
inline int | int |
ait_clrVars(array_t * __restrict vars) |
ait_clrVars(array_t * __restrict vars) |
{ |
{ |
register int i; |
register int i; |
Line 414 ait_clrVars(array_t * __restrict vars)
|
Line 648 ait_clrVars(array_t * __restrict vars)
|
* @vars = Variable array |
* @vars = Variable array |
* return: none |
* return: none |
*/ |
*/ |
inline void | void |
ait_freeVars(array_t ** __restrict vars) |
ait_freeVars(array_t ** __restrict vars) |
{ |
{ |
|
register int i; |
|
ait_val_t *v; |
|
|
if (!vars || !*vars) |
if (!vars || !*vars) |
return; |
return; |
|
|
ait_clrVars(*vars); | for (i = 0; i < array_Size(*vars); i++) |
array_Free(*vars); | if ((v = array(*vars, i, ait_val_t*))) { |
| /* free memory if isn't zero copy */ |
| if (!AIT_IN(v)) { |
| AIT_FREE_VAL(v); |
| if ((*vars)->arr_data[i]) |
| e_free((*vars)->arr_data[i]); |
| } else |
| AIT_FREE_VAL(v); |
| (*vars)->arr_data[i] = NULL; |
| } |
| (*vars)->arr_last = -1; |
| |
array_Destroy(vars); |
array_Destroy(vars); |
} |
} |
|
|
|
/* |
|
* ait_resideVars() - Calculate footprint of resided variables into array |
|
* |
|
* @vars = Variable array |
|
* return: bytes for whole array |
|
*/ |
|
size_t |
|
ait_resideVars(array_t * __restrict vars) |
|
{ |
|
size_t ret = 0; |
|
register int i; |
|
|
|
if (vars) { |
|
ret = array_Size(vars) * sizeof(ait_val_t); |
|
for (i = 0; i < array_Size(vars); i++) |
|
switch (AIT_TYPE(array(vars, i, ait_val_t*))) { |
|
case buffer: |
|
case string: |
|
case data: |
|
case ptr: |
|
ret += AIT_LEN(array(vars, i, ait_val_t*)); |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
|
/* |
/* |
* ait_allocVar() - Allocate memory for variable |
* ait_allocVar() - Allocate memory for variable |
* |
* |
* return: NULL error or new variable, after use free variable with ait_freeVar() |
* return: NULL error or new variable, after use free variable with ait_freeVar() |
*/ |
*/ |
inline ait_val_t * | ait_val_t * |
ait_allocVar(void) |
ait_allocVar(void) |
{ |
{ |
ait_val_t *v = NULL; |
ait_val_t *v = NULL; |
Line 452 ait_allocVar(void)
|
Line 730 ait_allocVar(void)
|
* @val = Variable |
* @val = Variable |
* return: none |
* return: none |
*/ |
*/ |
inline void | void |
ait_freeVar(ait_val_t ** __restrict val) |
ait_freeVar(ait_val_t ** __restrict val) |
{ |
{ |
if (val && *val) { |
if (val && *val) { |
Line 580 _cmp_arr_val_desc(const void *a, const void *b)
|
Line 858 _cmp_arr_val_desc(const void *a, const void *b)
|
* @cmp = Custom compare function for sorting. If =NULL compare by value |
* @cmp = Custom compare function for sorting. If =NULL compare by value |
* return: none |
* return: none |
*/ |
*/ |
inline void | void |
ait_sortVarsByVal(array_t * __restrict vars, int order, int (*cmp)(const void*, const void*)) |
ait_sortVarsByVal(array_t * __restrict vars, int order, int (*cmp)(const void*, const void*)) |
{ |
{ |
if (!vars) |
if (!vars) |
return; |
return; |
|
|
if (cmp) |
if (cmp) |
qsort(vars->arr_data, vars->arr_num, sizeof(void*), cmp); | qsort(vars->arr_data, vars->arr_num, sizeof(uintptr_t), cmp); |
else if (order) |
else if (order) |
qsort(vars->arr_data, vars->arr_num, sizeof(void*), _cmp_arr_val_desc); | qsort(vars->arr_data, vars->arr_num, sizeof(uintptr_t), _cmp_arr_val_desc); |
else |
else |
qsort(vars->arr_data, vars->arr_num, sizeof(void*), _cmp_arr_val_asc); | qsort(vars->arr_data, vars->arr_num, sizeof(uintptr_t), _cmp_arr_val_asc); |
} |
} |
|
|
/* |
/* |
Line 601 ait_sortVarsByVal(array_t * __restrict vars, int order
|
Line 879 ait_sortVarsByVal(array_t * __restrict vars, int order
|
* @order = Sort order. If =0 ascend or !=0 descend |
* @order = Sort order. If =0 ascend or !=0 descend |
* return: none |
* return: none |
*/ |
*/ |
inline void | void |
ait_sortVarsByKey(array_t * __restrict vars, int order) |
ait_sortVarsByKey(array_t * __restrict vars, int order) |
{ |
{ |
if (!vars) |
if (!vars) |
return; |
return; |
|
|
if (order) |
if (order) |
qsort(vars->arr_data, vars->arr_num, sizeof(void*), _cmp_arr_key_desc); | qsort(vars->arr_data, vars->arr_num, sizeof(uintptr_t), _cmp_arr_key_desc); |
else |
else |
qsort(vars->arr_data, vars->arr_num, sizeof(void*), _cmp_arr_key_asc); | qsort(vars->arr_data, vars->arr_num, sizeof(uintptr_t), _cmp_arr_key_asc); |
} |
} |
|
|
/* |
/* |
Line 634 ait_findKeyVars(array_t * __restrict vars, u_short key
|
Line 912 ait_findKeyVars(array_t * __restrict vars, u_short key
|
if (array_Copy(&tmp, vars) == -1) |
if (array_Copy(&tmp, vars) == -1) |
return NULL; |
return NULL; |
else |
else |
qsort(tmp->arr_data, tmp->arr_num, sizeof(void*), _cmp_arr_key_asc); | qsort(tmp->arr_data, tmp->arr_num, sizeof(uintptr_t), _cmp_arr_key_asc); |
|
|
/* binary search */ |
/* binary search */ |
for (p = (const u_char*) tmp->arr_data, i = array_Size(tmp); i; i >>= 1) { |
for (p = (const u_char*) tmp->arr_data, i = array_Size(tmp); i; i >>= 1) { |
vv = (ait_val_t**) (p + (i >> 1) * sizeof(void*)); | vv = (ait_val_t**) (p + (i >> 1) * sizeof(uintptr_t)); |
if (!(key - AIT_KEY(*vv))) { /* found! */ |
if (!(key - AIT_KEY(*vv))) { /* found! */ |
v = *vv; |
v = *vv; |
break; |
break; |
} |
} |
if ((key - AIT_KEY(*vv)) > 0) { /* move right key > current */ |
if ((key - AIT_KEY(*vv)) > 0) { /* move right key > current */ |
p = (const u_char*) vv + sizeof(void*); | p = (const u_char*) vv + sizeof(uintptr_t); |
i--; |
i--; |
} /* else move left */ |
} /* else move left */ |
} |
} |
Line 712 ait_hashVar(ait_val_t * __restrict v, const char * __r
|
Line 990 ait_hashVar(ait_val_t * __restrict v, const char * __r
|
* @vars = Variables |
* @vars = Variables |
* return -1 error or 0 ok |
* return -1 error or 0 ok |
*/ |
*/ |
inline int | int |
ait_hashKeyVars(array_t * __restrict vars) |
ait_hashKeyVars(array_t * __restrict vars) |
{ |
{ |
register int i; |
register int i; |
Line 733 ait_hashKeyVars(array_t * __restrict vars)
|
Line 1011 ait_hashKeyVars(array_t * __restrict vars)
|
* @key = Search string |
* @key = Search string |
* return: NULL error or not found, !=NULL valid element |
* return: NULL error or not found, !=NULL valid element |
*/ |
*/ |
inline ait_val_t * | ait_val_t * |
ait_findKeyHash(array_t * __restrict vars, const char * __restrict key) |
ait_findKeyHash(array_t * __restrict vars, const char * __restrict key) |
{ |
{ |
u_short k = 0; |
u_short k = 0; |
Line 754 ait_findKeyHash(array_t * __restrict vars, const char
|
Line 1032 ait_findKeyHash(array_t * __restrict vars, const char
|
* return: -1 error or >0 copied bytes to variable |
* return: -1 error or >0 copied bytes to variable |
*/ |
*/ |
int |
int |
io_sprintfVar(ait_val_t * __restrict v, const char *fmt, ...) | ait_sprintfVar(ait_val_t * __restrict v, const char *fmt, ...) |
{ |
{ |
int ret = 0; |
int ret = 0; |
va_list lst; |
va_list lst; |
char *str = NULL; | char str[STRSIZ] = { [0 ... STRSIZ - 1] = 0 }; |
|
|
if (!v || !fmt) |
if (!v || !fmt) |
return -1; |
return -1; |
|
|
va_start(lst, fmt); |
va_start(lst, fmt); |
ret = vasprintf(&str, fmt, lst); | ret = vsnprintf(str, sizeof str - 1, fmt, lst); |
va_end(lst); |
va_end(lst); |
|
|
if (str && ret > -1) { | if (ret > -1) { |
AIT_FREE_VAL(v); |
AIT_FREE_VAL(v); |
AIT_SET_STR(v, str); |
AIT_SET_STR(v, str); |
} else |
} else |
LOGERR; |
LOGERR; |
|
|
if (str) |
|
free(str); |
|
return ret; |
return ret; |
} |
} |
|
|
Line 787 io_sprintfVar(ait_val_t * __restrict v, const char *fm
|
Line 1063 io_sprintfVar(ait_val_t * __restrict v, const char *fm
|
* @... = data |
* @... = data |
* return: -1 error or 0 ok |
* return: -1 error or 0 ok |
*/ |
*/ |
inline int | int |
ait_setlikeVar(ait_val_t * __restrict v, ait_type_t t, u_int l, ...) |
ait_setlikeVar(ait_val_t * __restrict v, ait_type_t t, u_int l, ...) |
{ |
{ |
va_list lst; |
va_list lst; |
Line 822 ait_setlikeVar(ait_val_t * __restrict v, ait_type_t t,
|
Line 1098 ait_setlikeVar(ait_val_t * __restrict v, ait_type_t t,
|
* @v = variable |
* @v = variable |
* return: return raw data |
* return: return raw data |
*/ |
*/ |
inline uint64_t | uint64_t |
ait_getlikeVar(ait_val_t * __restrict v) |
ait_getlikeVar(ait_val_t * __restrict v) |
{ |
{ |
if (!v) |
if (!v) |
Line 838 ait_getlikeVar(ait_val_t * __restrict v)
|
Line 1114 ait_getlikeVar(ait_val_t * __restrict v)
|
* @b = 2nd variable |
* @b = 2nd variable |
* return: 0 is equal or !=0 is different |
* return: 0 is equal or !=0 is different |
*/ |
*/ |
inline int | int |
ait_cmpVar(ait_val_t * __restrict a, ait_val_t * __restrict b) |
ait_cmpVar(ait_val_t * __restrict a, ait_val_t * __restrict b) |
{ |
{ |
intptr_t ret; |
intptr_t ret; |