diff --git a/src/wayland-util.c b/src/wayland-util.c index 7231346b..fd7e6be9 100644 --- a/src/wayland-util.c +++ b/src/wayland-util.c @@ -138,6 +138,16 @@ wl_array_add(struct wl_array *array, size_t size) return p; } +WL_EXPORT void +wl_array_remove_at(struct wl_array *array, size_t offset, size_t size) { + if (array->size < offset + size) + wl_abort("Cannot remove data: array of size %zu is smaller than %zu", array->size, offset+size); + + char *data = array->data; + memmove(&data[offset], &data[offset+size], array->size - offset - size); + array->size -= size; +} + WL_EXPORT int wl_array_copy(struct wl_array *array, struct wl_array *source) { diff --git a/src/wayland-util.h b/src/wayland-util.h index 98c72fde..22874553 100644 --- a/src/wayland-util.h +++ b/src/wayland-util.h @@ -576,7 +576,18 @@ wl_array_release(struct wl_array *array); */ void * wl_array_add(struct wl_array *array, size_t size); +/** + * Removes a chunk of the specified size at the specified offset + * + * \param array Array whose data is to be removed + * \param offset Offset to remove data at + * \param size Size of data to be removed + * + * \memberof wl_array + */ +void +wl_array_remove_at(struct wl_array *array, size_t offset, size_t size); /** * Copies the contents of \p source to \p array. *