]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
include: Use __has_builtin to detect __builtin_offsetof support
authorGuillem Jover <guillem@hadrons.org>
Tue, 20 Dec 2022 21:47:02 +0000 (22:47 +0100)
committerGuillem Jover <guillem@hadrons.org>
Sun, 12 Feb 2023 23:39:54 +0000 (00:39 +0100)
The __has_builtin operator is more specific and is supported by GCC
and Clang, while __is_identifier() is less specific and only supported
by Clang, so we should prefer the former whenever it is available, and
only fallback to use the latter when the former is missing and the
latter.

include/bsd/sys/cdefs.h

index ac18296a5e47a5a6f241fe519b95089015b960dd..126f4275c91342b65e24ade0fd533acac4735314 100644 (file)
@@ -37,6 +37,9 @@
 #ifndef __is_identifier
 #define __is_identifier(x) 1
 #endif
+#ifndef __has_builtin
+#define __has_builtin(x) !__is_identifier(x)
+#endif
 
 #ifdef LIBBSD_OVERLAY
 /*
  * require it.
  */
 #ifndef __offsetof
-# if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
+# if LIBBSD_GCC_VERSION >= 0x0401 || __has_builtin(__builtin_offsetof)
 #  define __offsetof(type, field)      __builtin_offsetof(type, field)
 # else
 #  ifndef __cplusplus