From 1507cc211f6ce5b4f20f83470eacf44755a0cdcc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 9 Aug 2024 23:26:25 -0400 Subject: bfstd: New sysoption() macro to check for POSIX option runtime support POSIX allows optional features to be supported at compile time but not necessarily at run time by defining _POSIX_OPTION to 0 and requiring users to check sysconf(_SC_OPTION) > 0. The new sysoption() macro simplifies the check. sighook() and bfs_spawn() now check for conditional runtime support for the relevant POSIX options. --- src/bfstd.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/bfstd.h') diff --git a/src/bfstd.h b/src/bfstd.h index afb5282..968c0ac 100644 --- a/src/bfstd.h +++ b/src/bfstd.h @@ -447,6 +447,19 @@ int xstrtofflags(const char **str, unsigned long long *set, unsigned long long * */ long xsysconf(int name); +/** + * Check for a POSIX option[1] at runtime. + * + * [1]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap02.html#tag_02_01_06 + * + * @param name + * The symbolic name of the POSIX option (e.g. SPAWN). + * @return + * The value of the option, either -1 or a date like 202405. + */ +#define sysoption(name) \ + (_POSIX_##name == 0 ? xsysconf(_SC_##name) : _POSIX_##name) + #include /** -- cgit v1.2.3