summaryrefslogtreecommitdiff
path: root/include/tinyff
diff options
context:
space:
mode:
authorWatson Wheeler <git@tazy.dev>2026-06-28 20:23:29 +1000
committerWatson Wheeler <git@tazy.dev>2026-06-28 20:23:29 +1000
commit41d4b92421308c15811c0cb7658a64ee6773e413 (patch)
tree0990893057e6020efe2fd0d6672cd1bf930b8ccc /include/tinyff
parent14928a180689981c9b9de4d1ad373bf9e2694e63 (diff)
feat(compat): Check system and processor compatibility
Signed-off-by: Watson Wheeler <git@tazy.dev>
Diffstat (limited to 'include/tinyff')
-rw-r--r--include/tinyff/common.h3
-rw-r--r--include/tinyff/compat.h43
2 files changed, 45 insertions, 1 deletions
diff --git a/include/tinyff/common.h b/include/tinyff/common.h
index d4215ed..766f0ab 100644
--- a/include/tinyff/common.h
+++ b/include/tinyff/common.h
@@ -7,6 +7,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <tinyff/stream.h>
+#include <tinyff/compat.h>
#ifdef USE_BENCH
@@ -138,4 +139,4 @@ typedef struct ff_ctx {
ff_ctx* ff_init(ff_allocator* allocator);
void ff_cleanup(ff_ctx* ctx);
-#endif \ No newline at end of file
+#endif
diff --git a/include/tinyff/compat.h b/include/tinyff/compat.h
new file mode 100644
index 0000000..0199513
--- /dev/null
+++ b/include/tinyff/compat.h
@@ -0,0 +1,43 @@
+#ifndef TINYFF_COMPAT_H_
+#define TINYFF_COMPAT_H_
+
+#if defined(__STDC_HOSTED__) && !(__STDC_HOSTED__ == 0)
+# define COMPAT_HOSTED 1
+#else
+# define COMPAT_HOSTED 0
+#endif
+
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
+# error "compat: ISO C99 or newer compiler required."
+#endif
+
+#include <limits.h>
+#include <stdint.h>
+
+#if INT_MAX < 32767
+# error "compat: 8-bit 'int' architectures are not supported."
+#endif
+
+#if INTPTR_MAX == INT32_MAX
+# define COMPAT_SZ_32 1
+#elif INTPTR_MAX == INT64_MAX
+# define COMPAT_SZ_64 1
+#endif
+
+// Static assertion fallback for c99
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+ // static_assert already in version
+# include <assert.h>
+#else
+ // c99 dummy
+# define COMPAT_STATIC_ASSERT(expr, msg) \
+ typedef char compat_assertion_failed##__LINE__[(expr) ? 1 : -1]
+
+# undef static_assert
+# define static_assert(expr, msg) COMPAT_STATIC_ASSERT(expr, msg)
+#endif
+
+static_assert(sizeof(uint8_t) == 1, "compat: broken uint8_t width");
+static_assert(sizeof(uint32_t) == 4, "compat: broken uint32_t width");
+
+#endif