summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-08-28 10:53:10 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-08-28 17:33:20 -0400
commitb3636fa8864913413455a050c5425447c9e98bc0 (patch)
tree4ade291bf5652e9e27535602b11edff5a78d08b8 /src
parentd1febdd40faf2f66a901c42377a6b6efaad1449c (diff)
downloadbfs-b3636fa8864913413455a050c5425447c9e98bc0.tar.xz
build: Move feature test macros to prelude.h
This replaces the explicit CPPFLAGS list in flags.mk with just `-include src/prelude.h`, shortening our compiler command lines and allowing them to be easily documented.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c1
-rw-r--r--src/alloc.h2
-rw-r--r--src/atomic.h2
-rw-r--r--src/bar.c1
-rw-r--r--src/bfs.h2
-rw-r--r--src/bfstd.c1
-rw-r--r--src/bfstd.h2
-rw-r--r--src/bftw.c1
-rw-r--r--src/bit.h2
-rw-r--r--src/color.c1
-rw-r--r--src/color.h2
-rw-r--r--src/ctx.h2
-rw-r--r--src/diag.c1
-rw-r--r--src/diag.h2
-rw-r--r--src/dir.c1
-rw-r--r--src/dir.h2
-rw-r--r--src/dstring.c1
-rw-r--r--src/dstring.h2
-rw-r--r--src/eval.c1
-rw-r--r--src/eval.h2
-rw-r--r--src/exec.c1
-rw-r--r--src/expr.h2
-rw-r--r--src/fsade.c1
-rw-r--r--src/fsade.h2
-rw-r--r--src/ioq.c1
-rw-r--r--src/ioq.h2
-rw-r--r--src/main.c4
-rw-r--r--src/mtab.c1
-rw-r--r--src/mtab.h2
-rw-r--r--src/opt.c1
-rw-r--r--src/parse.c1
-rw-r--r--src/prelude.h58
-rw-r--r--src/printf.c1
-rw-r--r--src/pwcache.c1
-rw-r--r--src/sanity.h2
-rw-r--r--src/sighook.c1
-rw-r--r--src/stat.c1
-rw-r--r--src/stat.h2
-rw-r--r--src/thread.c1
-rw-r--r--src/thread.h2
-rw-r--r--src/trie.c1
-rw-r--r--src/version.c2
-rw-r--r--src/xregex.c1
-rw-r--r--src/xspawn.c1
-rw-r--r--src/xspawn.h2
-rw-r--r--src/xtime.c1
46 files changed, 57 insertions, 69 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 43340f7..223d737 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "alloc.h"
#include "bfs.h"
diff --git a/src/alloc.h b/src/alloc.h
index 5113839..7b97b8c 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -8,8 +8,6 @@
#ifndef BFS_ALLOC_H
#define BFS_ALLOC_H
-#include "prelude.h"
-
#include "bfs.h"
#include <errno.h>
diff --git a/src/atomic.h b/src/atomic.h
index 5e29974..2682c29 100644
--- a/src/atomic.h
+++ b/src/atomic.h
@@ -8,8 +8,6 @@
#ifndef BFS_ATOMIC_H
#define BFS_ATOMIC_H
-#include "prelude.h"
-
#include "bfs.h"
#include <stdatomic.h>
diff --git a/src/bar.c b/src/bar.c
index c574790..24e51e9 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "bar.h"
#include "alloc.h"
diff --git a/src/bfs.h b/src/bfs.h
index 8820ab9..91c6540 100644
--- a/src/bfs.h
+++ b/src/bfs.h
@@ -8,8 +8,6 @@
#ifndef BFS_H
#define BFS_H
-#include "prelude.h"
-
// Standard versions
/** Possible __STDC_VERSION__ values. */
diff --git a/src/bfstd.c b/src/bfstd.c
index 5a6038d..b29fb7b 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "bfstd.h"
#include "bfs.h"
diff --git a/src/bfstd.h b/src/bfstd.h
index 67894cd..557f253 100644
--- a/src/bfstd.h
+++ b/src/bfstd.h
@@ -8,8 +8,6 @@
#ifndef BFS_BFSTD_H
#define BFS_BFSTD_H
-#include "prelude.h"
-
#include "bfs.h"
#include <stddef.h>
diff --git a/src/bftw.c b/src/bftw.c
index 351cc36..64991b0 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -18,7 +18,6 @@
* various helper functions to take fewer parameters.
*/
-#include "prelude.h"
#include "bftw.h"
#include "alloc.h"
diff --git a/src/bit.h b/src/bit.h
index 0c11895..c7530f1 100644
--- a/src/bit.h
+++ b/src/bit.h
@@ -8,8 +8,6 @@
#ifndef BFS_BIT_H
#define BFS_BIT_H
-#include "prelude.h"
-
#include "bfs.h"
#include <limits.h>
diff --git a/src/color.c b/src/color.c
index 0c38c7d..7f653b0 100644
--- a/src/color.c
+++ b/src/color.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "color.h"
#include "alloc.h"
diff --git a/src/color.h b/src/color.h
index 6102480..38f5ad7 100644
--- a/src/color.h
+++ b/src/color.h
@@ -8,8 +8,6 @@
#ifndef BFS_COLOR_H
#define BFS_COLOR_H
-#include "prelude.h"
-
#include "bfs.h"
#include "dstring.h"
diff --git a/src/ctx.h b/src/ctx.h
index 0b4be45..e532550 100644
--- a/src/ctx.h
+++ b/src/ctx.h
@@ -8,8 +8,6 @@
#ifndef BFS_CTX_H
#define BFS_CTX_H
-#include "prelude.h"
-
#include "alloc.h"
#include "bftw.h"
#include "diag.h"
diff --git a/src/diag.c b/src/diag.c
index 30525ac..590d45c 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "diag.h"
#include "alloc.h"
diff --git a/src/diag.h b/src/diag.h
index 2d05654..3bea9b2 100644
--- a/src/diag.h
+++ b/src/diag.h
@@ -8,8 +8,6 @@
#ifndef BFS_DIAG_H
#define BFS_DIAG_H
-#include "prelude.h"
-
#include "bfs.h"
#include "bfstd.h"
diff --git a/src/dir.c b/src/dir.c
index 0a93fe0..4bf72a1 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "dir.h"
#include "alloc.h"
diff --git a/src/dir.h b/src/dir.h
index 0008d45..4482003 100644
--- a/src/dir.h
+++ b/src/dir.h
@@ -8,8 +8,6 @@
#ifndef BFS_DIR_H
#define BFS_DIR_H
-#include "prelude.h"
-
#include "bfs.h"
#include <sys/types.h>
diff --git a/src/dstring.c b/src/dstring.c
index 2f3abc5..36ed2c7 100644
--- a/src/dstring.c
+++ b/src/dstring.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "dstring.h"
#include "alloc.h"
diff --git a/src/dstring.h b/src/dstring.h
index a6103e3..6d50bc8 100644
--- a/src/dstring.h
+++ b/src/dstring.h
@@ -8,8 +8,6 @@
#ifndef BFS_DSTRING_H
#define BFS_DSTRING_H
-#include "prelude.h"
-
#include "bfs.h"
#include "bfstd.h"
diff --git a/src/eval.c b/src/eval.c
index bbafadb..a97c73b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -5,7 +5,6 @@
* Implementation of all the primary expressions.
*/
-#include "prelude.h"
#include "eval.h"
#include "atomic.h"
diff --git a/src/eval.h b/src/eval.h
index 4dd7996..48184c7 100644
--- a/src/eval.h
+++ b/src/eval.h
@@ -9,8 +9,6 @@
#ifndef BFS_EVAL_H
#define BFS_EVAL_H
-#include "prelude.h"
-
struct bfs_ctx;
struct bfs_expr;
diff --git a/src/exec.c b/src/exec.c
index 8f78d7b..45c9f1d 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "exec.h"
#include "alloc.h"
diff --git a/src/expr.h b/src/expr.h
index a6edff1..f14b936 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -8,8 +8,6 @@
#ifndef BFS_EXPR_H
#define BFS_EXPR_H
-#include "prelude.h"
-
#include "color.h"
#include "eval.h"
#include "stat.h"
diff --git a/src/fsade.c b/src/fsade.c
index b10c851..30b3018 100644
--- a/src/fsade.c
+++ b/src/fsade.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "fsade.h"
#include "atomic.h"
diff --git a/src/fsade.h b/src/fsade.h
index 9c7d117..77cf82a 100644
--- a/src/fsade.h
+++ b/src/fsade.h
@@ -9,8 +9,6 @@
#ifndef BFS_FSADE_H
#define BFS_FSADE_H
-#include "prelude.h"
-
#include "bfs.h"
#define BFS_CAN_CHECK_ACL (BFS_HAS_ACL_GET_FILE || BFS_HAS_ACL_TRIVIAL)
diff --git a/src/ioq.c b/src/ioq.c
index 10d4536..f936ff8 100644
--- a/src/ioq.c
+++ b/src/ioq.c
@@ -118,7 +118,6 @@
* [1]: https://arxiv.org/abs/2201.02179
*/
-#include "prelude.h"
#include "ioq.h"
#include "alloc.h"
diff --git a/src/ioq.h b/src/ioq.h
index 8226941..458c9e7 100644
--- a/src/ioq.h
+++ b/src/ioq.h
@@ -8,8 +8,6 @@
#ifndef BFS_IOQ_H
#define BFS_IOQ_H
-#include "prelude.h"
-
#include "dir.h"
#include "stat.h"
diff --git a/src/main.c b/src/main.c
index 9f78522..da07508 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,6 +20,7 @@
* - bftw.[ch] (an extended version of nftw(3))
*
* - Utilities:
+ * - prelude.h (feature test macros; automatically included)
* - alloc.[ch] (memory allocation)
* - atomic.h (atomic operations)
* - bar.[ch] (a terminal status bar)
@@ -27,7 +28,6 @@
* - bfs.h (configuration and fundamental utilities)
* - bfstd.[ch] (standard library wrappers/polyfills)
* - color.[ch] (for pretty terminal colors)
- * - prelude.h (configuration and feature/platform detection)
* - diag.[ch] (formats diagnostic messages)
* - dir.[ch] (a directory API facade)
* - dstring.[ch] (a dynamic string library)
@@ -48,8 +48,6 @@
* - xtime.[ch] (date/time handling utilities)
*/
-#include "prelude.h"
-
#include "bfstd.h"
#include "ctx.h"
#include "diag.h"
diff --git a/src/mtab.c b/src/mtab.c
index a013e41..79f3100 100644
--- a/src/mtab.c
+++ b/src/mtab.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "mtab.h"
#include "alloc.h"
diff --git a/src/mtab.h b/src/mtab.h
index 67290c2..6c7d5cb 100644
--- a/src/mtab.h
+++ b/src/mtab.h
@@ -8,8 +8,6 @@
#ifndef BFS_MTAB_H
#define BFS_MTAB_H
-#include "prelude.h"
-
struct bfs_stat;
/**
diff --git a/src/opt.c b/src/opt.c
index f75d9c9..425a540 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -25,7 +25,6 @@
* effects are reachable at all, skipping the traversal if not.
*/
-#include "prelude.h"
#include "opt.h"
#include "bfs.h"
diff --git a/src/parse.c b/src/parse.c
index a90dc2d..57c60ae 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -8,7 +8,6 @@
* flags like always-true options, and skipping over paths wherever they appear.
*/
-#include "prelude.h"
#include "parse.h"
#include "alloc.h"
diff --git a/src/prelude.h b/src/prelude.h
index 5f7203e..a0cc2a1 100644
--- a/src/prelude.h
+++ b/src/prelude.h
@@ -2,12 +2,66 @@
// SPDX-License-Identifier: 0BSD
/**
- * Configuration and feature/platform detection.
+ * Praeludium.
+ *
+ * This header is automatically included in every translation unit, before any
+ * other headers, so it can set feature test macros[1][2]. This sets up our own
+ * mini-dialect of C, which includes
+ *
+ * - Standard C17 and POSIX.1 2024 features
+ * - Portable and platform-specific extensions
+ * - Convenience macros like `bool`, `alignof`, etc.
+ * - Common compiler extensions like __has_include()
+ *
+ * Further bfs-specific utilities are defined in "bfs.h".
+ *
+ * [1]: https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+ * [2]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html
*/
#ifndef BFS_PRELUDE_H
#define BFS_PRELUDE_H
+// Feature test macros
+
+/**
+ * Linux and BSD handle _POSIX_C_SOURCE differently: on Linux, it enables POSIX
+ * interfaces that are not visible by default. On BSD, it also *disables* most
+ * extensions, giving a strict POSIX environment. Since we want the extensions,
+ * we don't set _POSIX_C_SOURCE.
+ */
+// #define _POSIX_C_SOURCE 202405L
+
+/** openat() etc. */
+#define _ATFILE_SOURCE 1
+
+/** BSD-derived extensions. */
+#define _BSD_SOURCE 1
+
+/** glibc successor to _BSD_SOURCE. */
+#define _DEFAULT_SOURCE 1
+
+/** GNU extensions. */
+#define _GNU_SOURCE 1
+
+/** Use 64-bit off_t. */
+#define _FILE_OFFSET_BITS 64
+
+/** Use 64-bit time_t. */
+#define _TIME_BITS 64
+
+/** macOS extensions. */
+#if __APPLE__
+# define _DARWIN_C_SOURCE 1
+#endif
+
+/** Solaris extensions. */
+#if __sun
+# define __EXTENSIONS__ 1
+// https://illumos.org/man/3C/getpwnam#standard-conforming
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+
// Get the convenience macros that became standard spellings in C23
#if __STDC_VERSION__ < 202311L
@@ -20,7 +74,7 @@
/**
* C23 deprecates `noreturn void` in favour of `[[noreturn]] void`, so we expose
- * _noreturn instead with the other attributes.
+ * _noreturn instead with the other attributes in "bfs.h".
*/
// #include <stdnoreturn.h>
diff --git a/src/printf.c b/src/printf.c
index 39abdcc..30ec201 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "printf.h"
#include "alloc.h"
diff --git a/src/pwcache.c b/src/pwcache.c
index 35a9925..c2b575e 100644
--- a/src/pwcache.c
+++ b/src/pwcache.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "pwcache.h"
#include "alloc.h"
diff --git a/src/sanity.h b/src/sanity.h
index 17450a3..0b770cf 100644
--- a/src/sanity.h
+++ b/src/sanity.h
@@ -8,8 +8,6 @@
#ifndef BFS_SANITY_H
#define BFS_SANITY_H
-#include "prelude.h"
-
#include <stddef.h>
// Call macro(ptr, size) or macro(ptr, sizeof(*ptr))
diff --git a/src/sighook.c b/src/sighook.c
index d697895..861a0b5 100644
--- a/src/sighook.c
+++ b/src/sighook.c
@@ -17,7 +17,6 @@
* drop to zero. Once it does, the old pointer can be safely freed.
*/
-#include "prelude.h"
#include "sighook.h"
#include "alloc.h"
diff --git a/src/stat.c b/src/stat.c
index 9f2918d..e99e711 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "stat.h"
#include "atomic.h"
diff --git a/src/stat.h b/src/stat.h
index a3da1bf..8d0bd9b 100644
--- a/src/stat.h
+++ b/src/stat.h
@@ -12,8 +12,6 @@
#ifndef BFS_STAT_H
#define BFS_STAT_H
-#include "prelude.h"
-
#include "bfs.h"
#include <sys/stat.h>
diff --git a/src/thread.c b/src/thread.c
index c555d1f..d61ff8c 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "thread.h"
#include "bfstd.h"
diff --git a/src/thread.h b/src/thread.h
index 7ecda86..7d12468 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -8,8 +8,6 @@
#ifndef BFS_THREAD_H
#define BFS_THREAD_H
-#include "prelude.h"
-
#include <pthread.h>
/** Thread entry point type. */
diff --git a/src/trie.c b/src/trie.c
index 848f172..a92950b 100644
--- a/src/trie.c
+++ b/src/trie.c
@@ -81,7 +81,6 @@
* and insert intermediate singleton "jump" nodes when necessary.
*/
-#include "prelude.h"
#include "trie.h"
#include "alloc.h"
diff --git a/src/version.c b/src/version.c
index 2822927..7479a9f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -1,8 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
-
#include "bfs.h"
const char bfs_version[] = {
diff --git a/src/xregex.c b/src/xregex.c
index 52f8222..796544e 100644
--- a/src/xregex.c
+++ b/src/xregex.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "xregex.h"
#include "alloc.h"
diff --git a/src/xspawn.c b/src/xspawn.c
index 0b83c8d..b3eed79 100644
--- a/src/xspawn.c
+++ b/src/xspawn.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "xspawn.h"
#include "alloc.h"
diff --git a/src/xspawn.h b/src/xspawn.h
index 60ef1ab..9cfbaf7 100644
--- a/src/xspawn.h
+++ b/src/xspawn.h
@@ -8,8 +8,6 @@
#ifndef BFS_XSPAWN_H
#define BFS_XSPAWN_H
-#include "prelude.h"
-
#include <sys/resource.h>
#include <sys/types.h>
#include <unistd.h>
diff --git a/src/xtime.c b/src/xtime.c
index 75ace72..dd9b60f 100644
--- a/src/xtime.c
+++ b/src/xtime.c
@@ -1,7 +1,6 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "xtime.h"
#include "bfs.h"