aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-28 23:50:39 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-28 23:50:39 +0100
commitef5932ab035d37fa26c9a18773285e769b67abcf (patch)
tree6c5721309e91b3c8d5b86c2721287e5ca17682eb
parent733ed3d75f20fd43411a7ad2091494ff52bb8d8a (diff)
Assert POSIX when __has_include() is available
-rw-r--r--cbs.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/cbs.h b/cbs.h
index 504e96e..aa75101 100644
--- a/cbs.h
+++ b/cbs.h
@@ -20,6 +20,19 @@
#ifndef C_BUILD_SYSTEM_H
#define C_BUILD_SYSTEM_H
+/* Assert that the user is building for a supported platform. The only portable
+ way to check for POSIX is to validate that unistd.h exists. This is only
+ possible without compiler extensions in C23 (although some compilers support
+ it as an extension in earlier editions), so people compiling for pre-C23
+ might not get this error if on a bad platform, and may end up being a bit
+ confused.
+
+ It’s just a maybe though, this is nothing more than a sanity check for the
+ users sake. */
+#if defined(__has_include) && !__has_include(<unistd.h>)
+# error "Non-POSIX platform detected"
+#endif
+
#include <sys/stat.h>
#include <sys/wait.h>