summaryrefslogtreecommitdiff
path: root/ds.h
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-03 15:38:54 -0500
committerpommicket <pommicket@gmail.com>2023-01-03 15:38:54 -0500
commitbaae904ed2c97ba5c701442ec5ef6900715f785d (patch)
tree6e6c10265624510dd73bb8bd0213a59fc02e3617 /ds.h
parentc37d493327ded5952f46cbf39aef920e47c1d7d9 (diff)
switch from scancodes to keycodes
Diffstat (limited to 'ds.h')
-rw-r--r--ds.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/ds.h b/ds.h
index 397dcfa..a588be7 100644
--- a/ds.h
+++ b/ds.h
@@ -192,6 +192,13 @@ static void *arr_remove_(void *arr, size_t member_size, size_t index) {
}
}
+static void *arr_copy_(const void *arr, size_t member_size) {
+ void *new_arr = NULL;
+ arr_set_len_(&new_arr, member_size, arr_len(arr));
+ memcpy(new_arr, arr, member_size * arr_len(arr));
+ return new_arr;
+}
+
#ifdef __cplusplus
#define arr_cast_typeof(a) (decltype(a))
#elif defined __GNUC__
@@ -224,6 +231,7 @@ static void *arr_remove_(void *arr, size_t member_size, size_t index) {
#define arr_pop_last(a) ((a)[--arr_hdr_(a)->len])
#define arr_size_in_bytes(a) (arr_len(a) * sizeof *(a))
#define arr_lastp(a) ((a) ? &(a)[arr_len(a)-1] : NULL)
+#define arr_copy(a) arr_cast_typeof(a) arr_copy_((a), sizeof *(a))
#define arr_foreach_ptr_end(a, type, var, end) type *end = (a) + arr_len(a); \
for (type *var = (a); var != end; ++var)
// Iterate through each element of the array, setting var to a pointer to the element.