summaryrefslogtreecommitdiff
path: root/arr.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-21 19:13:40 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-21 19:13:40 -0500
commit46a02444bdeac16474e31c4e836b118c07f8f57f (patch)
tree3b8079c0e19704c5c0c45ca838c84a35d4ad608c /arr.c
parent8fca7beaf35cfc438d5d29f352f80dd18efe7d2e (diff)
trying to make clicking on directories work; not done yet
Diffstat (limited to 'arr.c')
-rw-r--r--arr.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/arr.c b/arr.c
index 0fc856f..93f6198 100644
--- a/arr.c
+++ b/arr.c
@@ -109,8 +109,6 @@ static inline void *arr_add_ptr_(void **arr, size_t member_size) {
return ret;
}
-#if 0
-// NOT TESTED
static inline void arr_set_len_(void **arr, size_t member_size, size_t n) {
if (n >= U32_MAX-1) {
// too big; free arr.
@@ -153,10 +151,10 @@ static inline void arr_set_len_(void **arr, size_t member_size, size_t n) {
memset((char *)hdr->data + hdr->len, 0, (n - hdr->len) * member_size);
}
hdr->len = (u32)n;
+ *arr = hdr->data;
}
}
#define arr_set_len(a, n) arr_set_len_((void **)&a, sizeof *(a), n)
-#endif
#ifdef __cplusplus
#define arr_cast_typeof(a) (decltype(a))
@@ -209,6 +207,20 @@ static inline void arr_set_len_(void **arr, size_t member_size, size_t n) {
} \
} while (0)
+
+static void arr_append_str_(char **a, char const *s) {
+ size_t curr_len = arr_len(*a);
+ size_t s_len = strlen(s);
+
+ if (curr_len) --curr_len; // don't include null terminator
+
+ arr_set_len(*a, curr_len + s_len + 1);
+ memcpy(*a + curr_len, s, s_len + 1);
+}
+
+// appends a C-string array with
+#define arr_append_str(a, s) arr_append_str_(&(a), (s))
+
static void arr_test(void) {
u32 *arr = NULL;
u32 i;