Add os_remove_in_array()
This can be used to remove members from an array. Signed-off-by: Emanuel Taube <emanuel.taube@gmail.com>
This commit is contained in:
parent
c1151e47d5
commit
064eb057ca
1 changed files with 15 additions and 0 deletions
|
@ -549,6 +549,21 @@ static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
|
||||||
return os_realloc(ptr, nmemb * size);
|
return os_realloc(ptr, nmemb * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* os_remove_in_array - Remove a member from an array by index
|
||||||
|
* @ptr: Pointer to the array
|
||||||
|
* @nmemb: Current member count of the array
|
||||||
|
* @size: The size per member of the array
|
||||||
|
* @idx: Index of the member to be removed
|
||||||
|
*/
|
||||||
|
static inline void os_remove_in_array(void *ptr, size_t nmemb, size_t size,
|
||||||
|
size_t idx)
|
||||||
|
{
|
||||||
|
if (idx < nmemb - 1)
|
||||||
|
os_memmove(((unsigned char *) ptr) + idx * size,
|
||||||
|
((unsigned char *) ptr) + (idx + 1) * size,
|
||||||
|
(nmemb - idx - 1) * size);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* os_strlcpy - Copy a string with size bound and NUL-termination
|
* os_strlcpy - Copy a string with size bound and NUL-termination
|
||||||
|
|
Loading…
Reference in a new issue