#ifndef CCAN_DARRAY_H
#define CCAN_DARRAY_H
-/* Originally taken from: http://ccodearchive.net/info/darray.html
+/* Originally taken from: https://ccodearchive.net/info/darray.html
* But modified for libxkbcommon. */
#include <stdlib.h>
#define darray_from_items(arr, items, count) do { \
unsigned __count = (count); \
darray_resize(arr, __count); \
- memcpy((arr).item, items, __count * sizeof(*(arr).item)); \
+ if (__count != 0) \
+ memcpy((arr).item, items, __count * sizeof(*(arr).item)); \
} while (0)
#define darray_copy(arr_to, arr_from) \
(idx) < (arr).size; \
(idx)++, (val)++)
+#define darray_foreach_reverse(i, arr) \
+ for ((i) = &(arr).item[(arr).size - 1]; (arr).size > 0 && (i) >= &(arr).item[0]; (i)--)
+
#endif /* CCAN_DARRAY_H */