defined(__sun__) || \
defined(__APPLE__)
# include <inttypes.h>
-#elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__)
+#elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__) || defined(__OpenBSD__)
# include <stdint.h>
#endif
#ifdef __linux__
# include <endian.h>
# include <byteswap.h>
-#elif defined(__MACH__)
+#elif defined(__MACH__) || defined(__FreeBSD__)
# include <machine/endian.h>
typedef unsigned long ulong;
-typedef unsigned int uint;
#endif
+#ifdef __FreeBSD__
+# include <sys/endian.h> /* htole32 and friends */
+#elif defined(__OpenBSD__)
+# include <endian.h>
+#endif
+
+#include <time.h>
typedef uint8_t __u8;
typedef uint16_t __u16;
# define uswap_64(x) _uswap_64(x, )
#endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined(__OpenBSD__)
+#define cpu_to_le16(x) htole16(x)
+#define cpu_to_le32(x) htole32(x)
+#define cpu_to_le64(x) htole64(x)
+#define le16_to_cpu(x) letoh16(x)
+#define le32_to_cpu(x) letoh32(x)
+#define le64_to_cpu(x) letoh64(x)
+#define cpu_to_be16(x) htobe16(x)
+#define cpu_to_be32(x) htobe32(x)
+#define cpu_to_be64(x) htobe64(x)
+#define be16_to_cpu(x) betoh16(x)
+#define be32_to_cpu(x) betoh32(x)
+#define be64_to_cpu(x) betoh64(x)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
# define cpu_to_le16(x) (x)
# define cpu_to_le32(x) (x)
# define cpu_to_le64(x) (x)
#else /* !USE_HOSTCC */
+#ifdef CONFIG_USE_STDINT
+/* Provided by gcc. */
+#include <stdint.h>
+#else
+/* Type for `void *' pointers. */
+typedef unsigned long int uintptr_t;
+#endif
+
#include <linux/string.h>
#include <linux/types.h>
#include <asm/byteorder.h>
-/* Types for `void *' pointers. */
-#if __WORDSIZE == 64
-typedef unsigned long int uintptr_t;
+#if __SIZEOF_LONG__ == 8
+# define __WORDSIZE 64
+#elif __SIZEOF_LONG__ == 4
+# define __WORDSIZE 32
#else
-typedef unsigned int uintptr_t;
-#endif
-
+/*
+ * Assume 32-bit for now - only newer toolchains support this feature and
+ * this is only required for sandbox support at present.
+ */
+#define __WORDSIZE 32
#endif
-/* compiler options */
-#define uninitialized_var(x) x = x
+#endif /* USE_HOSTCC */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)