mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
replace: add ARRAY_INSERT_ELEMENT() helper
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
9053862b89
commit
9d8ff0d1e0
@ -885,6 +885,21 @@ typedef unsigned long long ptrdiff_t ;
|
|||||||
#define ARRAY_DEL_ELEMENT(a,i,n) \
|
#define ARRAY_DEL_ELEMENT(a,i,n) \
|
||||||
if((i)<((n)-1)){memmove(&((a)[(i)]),&((a)[(i)+1]),(sizeof(*(a))*((n)-(i)-1)));}
|
if((i)<((n)-1)){memmove(&((a)[(i)]),&((a)[(i)+1]),(sizeof(*(a))*((n)-(i)-1)));}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert an array element by moving the rest one up
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define ARRAY_INSERT_ELEMENT(__array,__old_last_idx,__new_elem,__new_idx) do { \
|
||||||
|
if ((__new_idx) < (__old_last_idx)) { \
|
||||||
|
const void *__src = &((__array)[(__new_idx)]); \
|
||||||
|
void *__dst = &((__array)[(__new_idx)+1]); \
|
||||||
|
size_t __num = (__old_last_idx)-(__new_idx); \
|
||||||
|
size_t __len = sizeof(*(__array)) * __num; \
|
||||||
|
memmove(__dst, __src, __len); \
|
||||||
|
} \
|
||||||
|
(__array)[(__new_idx)] = (__new_elem); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pointer difference macro
|
* Pointer difference macro
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user