Guard non-portable forwarded includes These headers are not available on Windows. <bsd/sys/cdefs.h> ensures that __has_include() and __has_include_next() are defined. Signed-off-by: Guillem Jover <guillem@hadrons.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
diff --git a/include/bsd/err.h b/include/bsd/err.h
index 12fd051..cf043e4 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -26,20 +26,20 @@
*/
#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<err.h>)
#include_next <err.h>
+#endif
#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<err.h>)
#include <err.h>
#endif
+#endif
#ifndef LIBBSD_ERR_H
#define LIBBSD_ERR_H
-#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
-#else
-#include <bsd/sys/cdefs.h>
-#endif
-
#include <stdarg.h>
__BEGIN_DECLS
diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index a6505e9..48c3be8 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -25,9 +25,15 @@
*/
#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<getopt.h>)
#include_next <getopt.h>
+#endif
#include <unistd.h>
#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<getopt.h>)
#include <getopt.h>
+#endif
#include <bsd/unistd.h>
#endif
diff --git a/include/bsd/sys/endian.h b/include/bsd/sys/endian.h
index 1af844c..a4a8e9c 100644
--- a/include/bsd/sys/endian.h
+++ b/include/bsd/sys/endian.h
@@ -27,10 +27,16 @@
*/
#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<endian.h>)
#include_next <endian.h>
+#endif
#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<endian.h>)
#include <endian.h>
#endif
+#endif
#ifndef LIBBSD_SYS_ENDIAN_H
#define LIBBSD_SYS_ENDIAN_H
diff --git a/include/bsd/sys/time.h b/include/bsd/sys/time.h
index 0aaf0e2..1eaa76b 100644
--- a/include/bsd/sys/time.h
+++ b/include/bsd/sys/time.h
@@ -33,10 +33,16 @@
*/
#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<sys/time.h>)
#include_next <sys/time.h>
+#endif
#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<sys/time.h>)
#include <sys/time.h>
#endif
+#endif
#ifndef LIBBSD_SYS_TIME_H
#define LIBBSD_SYS_TIME_H
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index c25977d..167241b 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -26,19 +26,20 @@
*/
#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<unistd.h>)
#include_next <unistd.h>
+#endif
#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<unistd.h>)
#include <unistd.h>
#endif
+#endif
#ifndef LIBBSD_UNISTD_H
#define LIBBSD_UNISTD_H
-#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
-#else
-#include <bsd/sys/cdefs.h>
-#endif
#include <sys/stat.h>
#if !defined(S_ISTXT) && defined(S_ISVTX)