aboutsummaryrefslogtreecommitdiff
path: root/libffwd/alloc.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-29 12:54:13 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-29 12:54:13 +0200
commit91871be6ece9317c5d49353f6474583e7e28168d (patch)
tree8cabf2546322a9e1b724bf8413f32de54378824f /libffwd/alloc.h
parent35ab9c12ba4d396e6cba99d6ea947e26becedad4 (diff)
downloadlangdet-91871be6ece9317c5d49353f6474583e7e28168d.tar.gz
langdet-91871be6ece9317c5d49353f6474583e7e28168d.zip
Add native CPU language detection CLI
Diffstat (limited to 'libffwd/alloc.h')
-rw-r--r--libffwd/alloc.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/libffwd/alloc.h b/libffwd/alloc.h
new file mode 100644
index 0000000..a12ee7a
--- /dev/null
+++ b/libffwd/alloc.h
@@ -0,0 +1,31 @@
+#ifndef FFWD_ALLOC_H
+#define FFWD_ALLOC_H
+
+#include <stddef.h>
+
+/* Checked size arithmetic and typed allocation helpers.
+ * Return -1 or NULL on overflow/allocation failure.
+ * realloc_* leave the original pointer unchanged on failure. */
+
+/* out = a * b, or -1 if the product overflows size_t. */
+int mul_size(size_t a, size_t b, size_t *out);
+
+/* out = a + b, or -1 if the sum overflows size_t. */
+int add_size(size_t a, size_t b, size_t *out);
+
+/* Grow sequence capacity without shrinking. */
+int grow_cap(int current, int needed, int *out);
+
+/* realloc *ptr to hold count floats; *ptr unchanged on failure. */
+int realloc_floats(float **ptr, size_t count);
+
+/* malloc count floats, NULL on overflow/failure. */
+float *malloc_floats(size_t count);
+
+/* realloc *ptr to hold rows*cols floats; -1 on negative dims/overflow/failure. */
+int realloc_floats_2d(float **ptr, int rows, int cols);
+
+/* realloc *ptr to hold count ints; *ptr unchanged on failure. */
+int realloc_ints(int **ptr, size_t count);
+
+#endif /* FFWD_ALLOC_H */