From 377b427491bcbf00e97fe02f69ef253e5ea3a53b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 29 May 2024 11:51:10 -0400 Subject: bit: Use if it exists, even without -std=c23 glibc added an implementation in 2.39. --- src/bit.h | 6 +++--- src/prelude.h | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bit.h b/src/bit.h index 880ccd6..c494130 100644 --- a/src/bit.h +++ b/src/bit.h @@ -12,7 +12,7 @@ #include #include -#if __STDC_VERSION__ >= C23 +#if BFS_HAS_STDBIT_H # include #endif @@ -226,7 +226,7 @@ static inline uint8_t bswap_u8(uint8_t n) { // C23 polyfill: bit utilities -#if __STDC_VERSION__ >= C23 +#if __STDC_VERSION_STDBIT_H__ >= C23 # define count_ones stdc_count_ones # define count_zeros stdc_count_zeros # define leading_zeros stdc_leading_zeros @@ -374,7 +374,7 @@ UINT_OVERLOADS(BIT_CEIL) #define bit_floor(n) UINT_SELECT(n, bit_floor)(n) #define bit_ceil(n) UINT_SELECT(n, bit_ceil)(n) -#endif // __STDC_VERSION__ < C23 +#endif // __STDC_VERSION_STDBIT_H__ < C23 #define ROTATE_LEFT(type, suffix, width) \ static inline type rotate_left##suffix(type n, int c) { \ diff --git a/src/prelude.h b/src/prelude.h index 3521fe8..c4edcb2 100644 --- a/src/prelude.h +++ b/src/prelude.h @@ -50,6 +50,9 @@ extern const char bfs_version[]; #if __has_include() # define BFS_HAS_PATHS_H true #endif +#if __has_include() +# define BFS_HAS_STDBIT_H true +#endif #if __has_include() # define BFS_HAS_SYS_EXTATTR_H true #endif @@ -76,6 +79,7 @@ extern const char bfs_version[]; #define BFS_HAS_MNTENT_H __GLIBC__ #define BFS_HAS_PATHS_H true +#define BFS_HAS_STDBIT_H (__STDC_VERSION__ >= C23) #define BFS_HAS_SYS_EXTATTR_H __FreeBSD__ #define BFS_HAS_SYS_MKDEV_H false #define BFS_HAS_SYS_PARAM_H true -- cgit v1.2.3