summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-22 20:23:05 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-22 20:23:05 +0200
commit242b87209b778d033d1da828ae9ec47170c17f38 (patch)
tree5394ab5babacc3c8cf542ab113ffe4a2a6c0edf9
parent3e6812f8f97ba884f39b01200e2bedeed89cf5c2 (diff)
downloadkit-242b87209b778d033d1da828ae9ec47170c17f38.zip
fix single header
-rw-r--r--.gitignore1
-rw-r--r--gen_gl.c11
-rw-r--r--gen_inl.c5
-rw-r--r--include/kit.inl.h46
4 files changed, 59 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index b846915..3a26fa3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/*build*/
*.swp
gen_inl
+gen_gl
diff --git a/gen_gl.c b/gen_gl.c
new file mode 100644
index 0000000..117d9bc
--- /dev/null
+++ b/gen_gl.c
@@ -0,0 +1,11 @@
+#if 0
+gcc -fsanitize=address,undefined,leak gen_gl.c -o gen_gl && ./gen_gl
+exit
+#endif
+
+#define KIT_IMPLEMENTATION
+#include "include/kit.inl.h"
+
+int main(int argc, char **argv) {
+ return 0;
+}
diff --git a/gen_inl.c b/gen_inl.c
index c6f5d3c..1e99058 100644
--- a/gen_inl.c
+++ b/gen_inl.c
@@ -36,6 +36,7 @@ char *IMPL[] = { "source/kit/allocator.c",
"source/kit/atomic.win32.c",
"source/kit/threads.posix.c",
"source/kit/threads.win32.c",
+ "source/kit/array_ref.c",
"source/kit/dynamic_array.c",
"source/kit/string_builder.c",
"source/kit/input_stream.c",
@@ -144,9 +145,9 @@ int main(int argc, char **argv) {
"===========\n");
fprintf(out, "//\n");
fprintf(out, "// kit.inl.h\n");
- fprintf(out, "// https://guattari.tech/git/?p=kit.git;a=tree\n");
+ fprintf(out, "// https://guattari.tech/kit.git\n");
fprintf(out, "//\n");
- fprintf(out, "// Header-only utility library for C.\n");
+ fprintf(out, "// Single header-only utility library for C.\n");
fprintf(out, "//\n");
fprintf(out, "// "
"====================================================="
diff --git a/include/kit.inl.h b/include/kit.inl.h
index 1b66297..9752919 100644
--- a/include/kit.inl.h
+++ b/include/kit.inl.h
@@ -1,9 +1,9 @@
// ================================================================
//
// kit.inl.h
-// https://guattari.tech/git/?p=kit.git;a=tree
+// https://guattari.tech/kit.git
//
-// Header-only utility library for C.
+// Single header-only utility library for C.
//
// ================================================================
//
@@ -2869,6 +2869,48 @@ void thrd_yield(void) {
#endif
/*********************************************************************
* *
+ * File: source/kit/array_ref.c *
+ * *
+ *********************************************************************/
+#include <string.h>
+i8 kit_ar_equal_bytes(i64 left_element_size, i64 left_size,
+ void *left_data, i64 right_element_size,
+ i64 right_size, void *right_data) {
+ i64 i;
+ if (left_element_size != right_element_size)
+ return 0;
+ if (left_size != right_size)
+ return 0;
+ for (i = 0; i < left_size; i++)
+ if (memcmp((u8 *) left_data + i * left_element_size,
+ (u8 *) right_data + i * left_element_size,
+ left_element_size) != 0)
+ return 0;
+ return 1;
+}
+i8 kit_ar_compare(i64 left_element_size, i64 left_size,
+ void *left_data, i64 right_element_size,
+ i64 right_size, void *right_data,
+ kit_ar_compare_fn compare) {
+ i64 i;
+ if (left_element_size < right_element_size)
+ return -1;
+ if (left_element_size > right_element_size)
+ return 1;
+ for (i = 0; i < left_size && i < right_size; i++) {
+ i8 c = compare((u8 *) left_data + i * left_element_size,
+ (u8 *) right_data + i * left_element_size);
+ if (c != 0)
+ return c;
+ }
+ if (left_size < right_size)
+ return -1;
+ if (left_size > right_size)
+ return 1;
+ return 0;
+}
+/*********************************************************************
+ * *
* File: source/kit/dynamic_array.c *
* *
*********************************************************************/