summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Makefile4
-rw-r--r--include/arpa/inet.h11
-rw-r--r--sys/arch/alpha/include/endian.h8
-rw-r--r--sys/arch/amd64/include/endian.h13
-rw-r--r--sys/arch/arm/include/endian.h6
-rw-r--r--sys/arch/hppa/include/endian.h8
-rw-r--r--sys/arch/hppa64/include/endian.h8
-rw-r--r--sys/arch/i386/include/endian.h17
-rw-r--r--sys/arch/ia64/include/endian.h6
-rw-r--r--sys/arch/m88k/include/endian.h8
-rw-r--r--sys/arch/mips64/include/endian.h8
-rw-r--r--sys/arch/powerpc/include/endian.h7
-rw-r--r--sys/arch/sh/include/endian.h10
-rw-r--r--sys/arch/sparc/include/endian.h8
-rw-r--r--sys/arch/sparc64/include/endian.h26
-rw-r--r--sys/arch/vax/include/endian.h11
-rw-r--r--sys/netinet/in.h12
-rw-r--r--sys/sys/_endian.h244
-rw-r--r--sys/sys/endian.h308
-rw-r--r--sys/sys/types.h10
20 files changed, 415 insertions, 318 deletions
diff --git a/include/Makefile b/include/Makefile
index dcf891620c1..7b5219f8af4 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.191 2014/07/11 21:50:28 tedu Exp $
+# $OpenBSD: Makefile,v 1.192 2014/07/12 16:25:08 guenther Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
@@ -28,7 +28,7 @@ FILES+= ieeefp.h
.endif
MFILES= frame.h
-LFILES= fcntl.h syslog.h termios.h stdarg.h stdint.h varargs.h
+LFILES= endian.h fcntl.h syslog.h termios.h stdarg.h stdint.h varargs.h
DIRS= arpa protocols rpc rpcsvc
LDIRS= crypto ddb dev isofs miscfs msdosfs net netinet netinet6 \
diff --git a/include/arpa/inet.h b/include/arpa/inet.h
index d653736d2b8..34828d05311 100644
--- a/include/arpa/inet.h
+++ b/include/arpa/inet.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet.h,v 1.15 2012/12/05 23:19:57 deraadt Exp $ */
+/* $OpenBSD: inet.h,v 1.16 2014/07/12 16:25:08 guenther Exp $ */
/*
* ++Copyright++ 1983, 1993
@@ -62,7 +62,14 @@
/* External definitions for functions in inet(3) */
#include <sys/types.h>
-#include <machine/endian.h>
+
+/* <sys/_endian.h> is pulled in by <sys/types.h> */
+#ifndef htons
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
#ifndef _SOCKLEN_T_DEFINED_
#define _SOCKLEN_T_DEFINED_
diff --git a/sys/arch/alpha/include/endian.h b/sys/arch/alpha/include/endian.h
index 5ebf5b94a44..216013160c2 100644
--- a/sys/arch/alpha/include/endian.h
+++ b/sys/arch/alpha/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.13 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.14 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -28,8 +28,10 @@
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _LITTLE_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/amd64/include/endian.h b/sys/arch/amd64/include/endian.h
index 7889a374f47..14c451e46f5 100644
--- a/sys/arch/amd64/include/endian.h
+++ b/sys/arch/amd64/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.5 2011/03/12 22:27:48 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -30,32 +30,35 @@
#ifdef __GNUC__
#define __swap32md(x) __statement({ \
- u_int32_t __swap32md_x = (x); \
+ __uint32_t __swap32md_x = (x); \
\
__asm ("bswap %0" : "+r" (__swap32md_x)); \
__swap32md_x; \
})
#define __swap64md(x) __statement({ \
- u_int64_t __swap64md_x = (x); \
+ __uint64_t __swap64md_x = (x); \
\
__asm ("bswapq %0" : "+r" (__swap64md_x)); \
__swap64md_x; \
})
#define __swap16md(x) __statement({ \
- u_int16_t __swap16md_x = (x); \
+ __uint16_t __swap16md_x = (x); \
\
__asm ("rorw $8, %w0" : "+r" (__swap16md_x)); \
__swap16md_x; \
})
/* Tell sys/endian.h we have MD variants of the swap macros. */
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/arm/include/endian.h b/sys/arch/arm/include/endian.h
index 1c370350a02..0c12941585a 100644
--- a/sys/arch/arm/include/endian.h
+++ b/sys/arch/arm/include/endian.h
@@ -1,10 +1,12 @@
-/* $OpenBSD: endian.h,v 1.6 2011/11/08 17:06:51 deraadt Exp $ */
+/* $OpenBSD: endian.h,v 1.7 2014/07/12 16:25:08 guenther Exp $ */
#ifndef _ARM_ENDIAN_H_
#define _ARM_ENDIAN_H_
#define _BYTE_ORDER _LITTLE_ENDIAN
#define __STRICT_ALIGNMENT
-#include <sys/endian.h>
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
#endif /* _ARM_ENDIAN_H_ */
diff --git a/sys/arch/hppa/include/endian.h b/sys/arch/hppa/include/endian.h
index 0b61d7e2790..b31fe08029a 100644
--- a/sys/arch/hppa/include/endian.h
+++ b/sys/arch/hppa/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.11 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.12 2014/07/12 16:25:08 guenther Exp $ */
/*
* Copyright (c) 1998-2004 Michael Shalayeff
@@ -30,8 +30,10 @@
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* !_MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/hppa64/include/endian.h b/sys/arch/hppa64/include/endian.h
index e3eccb65cb3..d73001d137a 100644
--- a/sys/arch/hppa64/include/endian.h
+++ b/sys/arch/hppa64/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.3 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.4 2014/07/12 16:25:08 guenther Exp $ */
/*
* Copyright (c) 2005 Michael Shalayeff
@@ -21,8 +21,10 @@
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* !_MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/i386/include/endian.h b/sys/arch/i386/include/endian.h
index 817d6c6abb4..1f58500c862 100644
--- a/sys/arch/i386/include/endian.h
+++ b/sys/arch/i386/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.17 2011/03/12 04:03:04 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.18 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -30,31 +30,34 @@
#ifdef __GNUC__
#define __swap32md(x) __statement({ \
- u_int32_t __swap32md_x = (x); \
+ __uint32_t __swap32md_x = (x); \
\
__asm ("bswap %0" : "+r" (__swap32md_x)); \
__swap32md_x; \
})
#define __swap64md(x) __statement({ \
- u_int64_t __swap64md_x = (x); \
+ __uint64_t __swap64md_x = (x); \
\
- (u_int64_t)__swap32md(__swap64md_x >> 32) | \
- (u_int64_t)__swap32md(__swap64md_x & 0xffffffff) << 32; \
+ (__uint64_t)__swap32md(__swap64md_x >> 32) | \
+ (__uint64_t)__swap32md(__swap64md_x & 0xffffffff) << 32; \
})
#define __swap16md(x) __statement({ \
- u_int16_t __swap16md_x = (x); \
+ __uint16_t __swap16md_x = (x); \
\
__asm ("rorw $8, %w0" : "+r" (__swap16md_x)); \
__swap16md_x; \
})
/* Tell sys/endian.h we have MD variants of the swap macros. */
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/ia64/include/endian.h b/sys/arch/ia64/include/endian.h
index bb775dbe727..f40b1e25cc2 100644
--- a/sys/arch/ia64/include/endian.h
+++ b/sys/arch/ia64/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.1 2011/07/04 23:29:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.2 2014/07/12 16:25:08 guenther Exp $ */
/*
* Written by Paul Irofti <pirofti@openbsd.org>. Public Domain.
@@ -7,9 +7,11 @@
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
+#define _BYTE_ORDER _LITTLE_ENDIAN
#define __STRICT_ALIGNMENT
-#define _BYTE_ORDER _LITTLE_ENDIAN
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/m88k/include/endian.h b/sys/arch/m88k/include/endian.h
index 0a2c32e80f0..3b5a4632ef9 100644
--- a/sys/arch/m88k/include/endian.h
+++ b/sys/arch/m88k/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.5 2011/03/23 16:54:35 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -28,9 +28,11 @@
#define _M88K_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _M88K_ENDIAN_H_ */
diff --git a/sys/arch/mips64/include/endian.h b/sys/arch/mips64/include/endian.h
index c8ecfde3bfc..3bc64bf92e0 100644
--- a/sys/arch/mips64/include/endian.h
+++ b/sys/arch/mips64/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.8 2014/03/11 19:45:27 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.9 2014/07/12 16:25:08 guenther Exp $ */
/*
* Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com)
@@ -40,8 +40,10 @@
#error "__MIPSEL__ or __MIPSEB__ must be defined to define BYTE_ORDER!!!"
#endif
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MIPS64_ENDIAN_H_ */
diff --git a/sys/arch/powerpc/include/endian.h b/sys/arch/powerpc/include/endian.h
index f8376e3be02..d8e4c5eb38c 100644
--- a/sys/arch/powerpc/include/endian.h
+++ b/sys/arch/powerpc/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.19 2014/03/25 04:25:06 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.20 2014/07/12 16:25:09 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -90,11 +90,14 @@ __swapm64(volatile __uint64_t *m, __uint64_t v)
__swapm32(a, v);
}
-#define MD_SWAPIO
+#define __HAVE_MD_SWAPIO
#endif /* _KERNEL */
#undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */
#define _BYTE_ORDER _BIG_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _POWERPC_ENDIAN_H_ */
diff --git a/sys/arch/sh/include/endian.h b/sys/arch/sh/include/endian.h
index 689b168d2ab..daba001f12b 100644
--- a/sys/arch/sh/include/endian.h
+++ b/sys/arch/sh/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.4 2011/03/23 16:54:36 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.5 2014/07/12 16:25:09 guenther Exp $ */
/* $NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $ */
/* Written by Manuel Bouyer. Public domain */
@@ -27,7 +27,7 @@
rval; \
})
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif /* __GNUC_ */
@@ -36,8 +36,10 @@
#else
#define _BYTE_ORDER _BIG_ENDIAN
#endif
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* !_SH_ENDIAN_H_ */
diff --git a/sys/arch/sparc/include/endian.h b/sys/arch/sparc/include/endian.h
index 530925bf188..a57f05395a8 100644
--- a/sys/arch/sparc/include/endian.h
+++ b/sys/arch/sparc/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.13 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.14 2014/07/12 16:25:09 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -28,8 +28,10 @@
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/sparc64/include/endian.h b/sys/arch/sparc64/include/endian.h
index 14d0ff09251..b2bb346d4ed 100644
--- a/sys/arch/sparc64/include/endian.h
+++ b/sys/arch/sparc64/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.5 2014/03/25 03:53:35 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:09 guenther Exp $ */
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
@@ -7,7 +7,7 @@
#ifdef _KERNEL
-#define ASI_P_L 0x88
+#define __ASI_P_L 0x88 /* == ASI_PRIMARY_LITTLE */
static inline __uint16_t
__mswap16(volatile __uint16_t *m)
@@ -16,7 +16,7 @@ __mswap16(volatile __uint16_t *m)
__asm("lduha [%1] %2, %0 ! %3"
: "=r" (v)
- : "r" (m), "n" (ASI_P_L), "m" (*m));
+ : "r" (m), "n" (__ASI_P_L), "m" (*m));
return (v);
}
@@ -28,7 +28,7 @@ __mswap32(volatile __uint32_t *m)
__asm("lduwa [%1] %2, %0 ! %3"
: "=r" (v)
- : "r" (m), "n" (ASI_P_L), "m" (*m));
+ : "r" (m), "n" (__ASI_P_L), "m" (*m));
return (v);
}
@@ -40,7 +40,7 @@ __mswap64(volatile __uint64_t *m)
__asm("ldxa [%1] %2, %0 ! %3"
: "=r" (v)
- : "r" (m), "n" (ASI_P_L), "m" (*m));
+ : "r" (m), "n" (__ASI_P_L), "m" (*m));
return (v);
}
@@ -50,7 +50,7 @@ __swapm16(volatile __uint16_t *m, __uint16_t v)
{
__asm("stha %1, [%2] %3 ! %0"
: "=m" (*m)
- : "r" (v), "r" (m), "n" (ASI_P_L));
+ : "r" (v), "r" (m), "n" (__ASI_P_L));
}
static inline void
@@ -58,7 +58,7 @@ __swapm32(volatile __uint32_t *m, __uint32_t v)
{
__asm("stwa %1, [%2] %3 ! %0"
: "=m" (*m)
- : "r" (v), "r" (m), "n" (ASI_P_L));
+ : "r" (v), "r" (m), "n" (__ASI_P_L));
}
static inline void
@@ -66,17 +66,19 @@ __swapm64(volatile __uint64_t *m, __uint64_t v)
{
__asm("stxa %1, [%2] %3 ! %0"
: "=m" (*m)
- : "r" (v), "r" (m), "n" (ASI_P_L));
+ : "r" (v), "r" (m), "n" (__ASI_P_L));
}
-#undef ASI_P_L
+#undef __ASI_P_L
-#define MD_SWAPIO
+#define __HAVE_MD_SWAPIO
#endif /* _KERNEL */
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/vax/include/endian.h b/sys/arch/vax/include/endian.h
index d3407e2a5d0..b8105016565 100644
--- a/sys/arch/vax/include/endian.h
+++ b/sys/arch/vax/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.16 2013/07/05 21:10:50 miod Exp $ */
+/* $OpenBSD: endian.h,v 1.17 2014/07/12 16:25:09 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -32,7 +32,7 @@
#define __swap64md __swap64gen
#define __swap32md(x) __statement({ \
- u_int32_t __swap32md_y, __swap32md_x = (x); \
+ __uint32_t __swap32md_y, __swap32md_x = (x); \
\
__asm ("rotl $-8, %1, %0; insv %0, $16, $8, %0; " \
"rotl $8, %1, %%r1; movb %%r1, %0" : \
@@ -41,7 +41,7 @@
})
#define __swap16md(x) __statement({ \
- u_int16_t __swap16md_y, __swap16md_x = (x); \
+ __uint16_t __swap16md_y, __swap16md_x = (x); \
\
__asm ("rotl $8, %1, %0; rotl $-8, %1, %%r1; movb %%r1, %0; " \
"movzwl %0, %0" : \
@@ -51,12 +51,15 @@
/* Tell sys/endian.h we have MD variants of the swap macros. */
#ifdef notyet
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 770905adb1d..9976b6cdde9 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.h,v 1.108 2014/04/25 09:44:38 mpi Exp $ */
+/* $OpenBSD: in.h,v 1.109 2014/07/12 16:25:08 guenther Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
@@ -42,7 +42,15 @@
#ifndef _KERNEL
#include <sys/types.h>
-#include <machine/endian.h>
+
+/* <sys/_endian.h> is pulled in by <sys/types.h> */
+#ifndef htons
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
+
#endif /* _KERNEL */
#ifndef _SA_FAMILY_T_DEFINED_
diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h
new file mode 100644
index 00000000000..c2e16a4a06f
--- /dev/null
+++ b/sys/sys/_endian.h
@@ -0,0 +1,244 @@
+/* $OpenBSD: _endian.h,v 1.1 2014/07/12 16:25:08 guenther Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Internal endianness macros. This pulls in <machine/endian.h> to
+ * get the correct setting direction for the platform and sets internal
+ * ('__' prefix) macros appropriately.
+ */
+
+#ifndef _SYS__ENDIAN_H_
+#define _SYS__ENDIAN_H_
+
+#include <sys/_types.h>
+
+#define __FROM_SYS__ENDIAN
+#include <machine/endian.h>
+#undef __FROM_SYS__ENDIAN
+
+#define _LITTLE_ENDIAN 1234
+#define _BIG_ENDIAN 4321
+#define _PDP_ENDIAN 3412
+
+#ifdef __GNUC__
+
+#define __swap16gen(x) __statement({ \
+ __uint16_t __swap16gen_x = (x); \
+ \
+ (__uint16_t)((__swap16gen_x & 0xff) << 8 | \
+ (__swap16gen_x & 0xff00) >> 8); \
+})
+
+#define __swap32gen(x) __statement({ \
+ __uint32_t __swap32gen_x = (x); \
+ \
+ (__uint32_t)((__swap32gen_x & 0xff) << 24 | \
+ (__swap32gen_x & 0xff00) << 8 | \
+ (__swap32gen_x & 0xff0000) >> 8 | \
+ (__swap32gen_x & 0xff000000) >> 24); \
+})
+
+#define __swap64gen(x) __statement({ \
+ __uint64_t __swap64gen_x = (x); \
+ \
+ (__uint64_t)((__swap64gen_x & 0xff) << 56 | \
+ (__swap64gen_x & 0xff00ULL) << 40 | \
+ (__swap64gen_x & 0xff0000ULL) << 24 | \
+ (__swap64gen_x & 0xff000000ULL) << 8 | \
+ (__swap64gen_x & 0xff00000000ULL) >> 8 | \
+ (__swap64gen_x & 0xff0000000000ULL) >> 24 | \
+ (__swap64gen_x & 0xff000000000000ULL) >> 40 | \
+ (__swap64gen_x & 0xff00000000000000ULL) >> 56); \
+})
+
+#else /* __GNUC__ */
+
+/* Note that these macros evaluate their arguments several times. */
+#define __swap16gen(x) \
+ (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8)
+
+#define __swap32gen(x) \
+ (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \
+ ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
+ ((__uint32_t)(x) & 0xff000000) >> 24)
+
+#define __swap64gen(x) \
+ (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \
+ ((__uint64_t)(x) & 0xff00ULL) << 40 | \
+ ((__uint64_t)(x) & 0xff0000ULL) << 24 | \
+ ((__uint64_t)(x) & 0xff000000ULL) << 8 | \
+ ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \
+ ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \
+ ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \
+ ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
+
+#endif /* __GNUC__ */
+
+/*
+ * Define __HAVE_MD_SWAP if you provide __swap{16,32}md functions/macros
+ * that are optimized for your architecture, These will be used for
+ * __swap{16,32} unless the argument is a constant and we are using GCC,
+ * where we can take advantage of the CSE phase much better by using the
+ * generic version.
+ */
+#ifdef __HAVE_MD_SWAP
+#if __GNUC__
+
+#define __swap16(x) __statement({ \
+ __uint16_t __swap16_x = (x); \
+ \
+ __builtin_constant_p(x) ? __swap16gen(__swap16_x) : \
+ __swap16md(__swap16_x); \
+})
+
+#define __swap32(x) __statement({ \
+ __uint32_t __swap32_x = (x); \
+ \
+ __builtin_constant_p(x) ? __swap32gen(__swap32_x) : \
+ __swap32md(__swap32_x); \
+})
+
+#define __swap64(x) __statement({ \
+ __uint64_t __swap64_x = (x); \
+ \
+ __builtin_constant_p(x) ? __swap64gen(__swap64_x) : \
+ __swap64md(__swap64_x); \
+})
+
+#else
+
+/* have MD macros, but not gcc */
+#define __swap16 __swap16md
+#define __swap32 __swap32md
+#define __swap64 __swap64md
+
+#endif /* __GNUC__ */
+
+#else /* __HAVE_MD_SWAP */
+#define __swap16 __swap16gen
+#define __swap32 __swap32gen
+#define __swap64 __swap64gen
+#endif /* __HAVE_MD_SWAP */
+
+#define __swap16_multi(v, n) do { \
+ __size_t __swap16_multi_n = (n); \
+ __uint16_t *__swap16_multi_v = (v); \
+ \
+ while (__swap16_multi_n) { \
+ *__swap16_multi_v = swap16(*__swap16_multi_v); \
+ __swap16_multi_v++; \
+ __swap16_multi_n--; \
+ } \
+} while (0)
+
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+
+#define _QUAD_HIGHWORD 1
+#define _QUAD_LOWWORD 0
+
+#define __htobe16 __swap16
+#define __htobe32 __swap32
+#define __htobe64 __swap64
+#define __htole16(x) ((__uint16_t)(x))
+#define __htole32(x) ((__uint32_t)(x))
+#define __htole64(x) ((__uint64_t)(x))
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __bemtoh16(_x) __mswap16(_x)
+#define __bemtoh32(_x) __mswap32(_x)
+#define __bemtoh64(_x) __mswap64(_x)
+
+#define __htobem16(_x, _v) __swapm16((_x), (_v))
+#define __htobem32(_x, _v) __swapm32((_x), (_v))
+#define __htobem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+
+#define _QUAD_HIGHWORD 0
+#define _QUAD_LOWWORD 1
+
+#define __htobe16(x) ((__uint16_t)(x))
+#define __htobe32(x) ((__uint32_t)(x))
+#define __htobe64(x) ((__uint64_t)(x))
+#define __htole16 __swap16
+#define __htole32 __swap32
+#define __htole64 __swap64
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __lemtoh16(_x) __mswap16(_x)
+#define __lemtoh32(_x) __mswap32(_x)
+#define __lemtoh64(_x) __mswap64(_x)
+
+#define __htolem16(_x, _v) __swapm16((_x), (_v))
+#define __htolem32(_x, _v) __swapm32((_x), (_v))
+#define __htolem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _BIG_ENDIAN */
+
+
+#ifdef _KERNEL
+/*
+ * Fill in the __hto[bl]em{16,32,64} and __[bl]emtoh{16,32,64} macros
+ * that haven't been defined yet
+ */
+
+#ifndef __bemtoh16
+#define __bemtoh16(_x) __htobe16(*(__uint16_t *)(_x))
+#define __bemtoh32(_x) __htobe32(*(__uint32_t *)(_x))
+#define __bemtoh64(_x) __htobe64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htobem16
+#define __htobem16(_x, _v) (*(__uint16_t *)(_x) = __htobe16(_v))
+#define __htobem32(_x, _v) (*(__uint32_t *)(_x) = __htobe32(_v))
+#define __htobem64(_x, _v) (*(__uint64_t *)(_x) = __htobe64(_v))
+#endif
+
+#ifndef __lemtoh16
+#define __lemtoh16(_x) __htole16(*(__uint16_t *)(_x))
+#define __lemtoh32(_x) __htole32(*(__uint32_t *)(_x))
+#define __lemtoh64(_x) __htole64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htolem16
+#define __htolem16(_x, _v) (*(__uint16_t *)(_x) = __htole16(_v))
+#define __htolem32(_x, _v) (*(__uint32_t *)(_x) = __htole32(_v))
+#define __htolem64(_x, _v) (*(__uint64_t *)(_x) = __htole64(_v))
+#endif
+#endif /* _KERNEL */
+
+#endif /* _SYS__ENDIAN_H_ */
diff --git a/sys/sys/endian.h b/sys/sys/endian.h
index cad62d5a76f..8f3c2e87c0c 100644
--- a/sys/sys/endian.h
+++ b/sys/sys/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.22 2014/07/10 03:16:13 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.23 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -36,113 +36,40 @@
#ifndef _SYS_ENDIAN_H_
#define _SYS_ENDIAN_H_
-#include <sys/cdefs.h>
-#include <sys/_types.h>
+#include <sys/_endian.h>
-#define _LITTLE_ENDIAN 1234
-#define _BIG_ENDIAN 4321
-#define _PDP_ENDIAN 3412
-
-#if __BSD_VISIBLE
+/* Public names */
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define BIG_ENDIAN _BIG_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
#define BYTE_ORDER _BYTE_ORDER
-#endif
-
-#ifdef __GNUC__
-
-#define __swap16gen(x) __statement({ \
- __uint16_t __swap16gen_x = (x); \
- \
- (__uint16_t)((__swap16gen_x & 0xff) << 8 | \
- (__swap16gen_x & 0xff00) >> 8); \
-})
-
-#define __swap32gen(x) __statement({ \
- __uint32_t __swap32gen_x = (x); \
- \
- (__uint32_t)((__swap32gen_x & 0xff) << 24 | \
- (__swap32gen_x & 0xff00) << 8 | \
- (__swap32gen_x & 0xff0000) >> 8 | \
- (__swap32gen_x & 0xff000000) >> 24); \
-})
-
-#define __swap64gen(x) __statement({ \
- __uint64_t __swap64gen_x = (x); \
- \
- (__uint64_t)((__swap64gen_x & 0xff) << 56 | \
- (__swap64gen_x & 0xff00ULL) << 40 | \
- (__swap64gen_x & 0xff0000ULL) << 24 | \
- (__swap64gen_x & 0xff000000ULL) << 8 | \
- (__swap64gen_x & 0xff00000000ULL) >> 8 | \
- (__swap64gen_x & 0xff0000000000ULL) >> 24 | \
- (__swap64gen_x & 0xff000000000000ULL) >> 40 | \
- (__swap64gen_x & 0xff00000000000000ULL) >> 56); \
-})
-#else /* __GNUC__ */
-
-/* Note that these macros evaluate their arguments several times. */
-#define __swap16gen(x) \
- (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8)
-
-#define __swap32gen(x) \
- (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \
- ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
- ((__uint32_t)(x) & 0xff000000) >> 24)
-
-#define __swap64gen(x) \
- (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \
- ((__uint64_t)(x) & 0xff00ULL) << 40 | \
- ((__uint64_t)(x) & 0xff0000ULL) << 24 | \
- ((__uint64_t)(x) & 0xff000000ULL) << 8 | \
- ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \
- ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \
- ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \
- ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
-
-#endif /* __GNUC__ */
/*
- * Define MD_SWAP if you provide swap{16,32}md functions/macros that are
- * optimized for your architecture, These will be used for swap{16,32}
- * unless the argument is a constant and we are using GCC, where we can
- * take advantage of the CSE phase much better by using the generic version.
+ * These are specified to be function-like macros to match the spec
*/
-#ifdef MD_SWAP
-#if __GNUC__
-
-#define __swap16(x) __statement({ \
- __uint16_t __swap16_x = (x); \
- \
- __builtin_constant_p(x) ? __swap16gen(__swap16_x) : \
- __swap16md(__swap16_x); \
-})
-
-#define __swap32(x) __statement({ \
- __uint32_t __swap32_x = (x); \
- \
- __builtin_constant_p(x) ? __swap32gen(__swap32_x) : \
- __swap32md(__swap32_x); \
-})
-
-#define __swap64(x) __statement({ \
- __uint64_t __swap64_x = (x); \
- \
- __builtin_constant_p(x) ? __swap64gen(__swap64_x) : \
- __swap64md(__swap64_x); \
-})
+#define htobe16(x) __htobe16(x)
+#define htobe32(x) __htobe32(x)
+#define htobe64(x) __htobe64(x)
+#define htole16(x) __htole16(x)
+#define htole32(x) __htole32(x)
+#define htole64(x) __htole64(x)
+
+/* POSIX names */
+#define be16toh(x) __htobe16(x)
+#define be32toh(x) __htobe32(x)
+#define be64toh(x) __htobe64(x)
+#define le16toh(x) __htole16(x)
+#define le32toh(x) __htole32(x)
+#define le64toh(x) __htole64(x)
-#endif /* __GNUC__ */
-#else /* MD_SWAP */
-#define __swap16 __swap16gen
-#define __swap32 __swap32gen
-#define __swap64 __swap64gen
-#endif /* MD_SWAP */
+#if __BSD_VISIBLE
+#define swap16(x) __swap16(x)
+#define swap32(x) __swap32(x)
+#define swap64(x) __swap64(x)
-#define __swap16_multi(v, n) do { \
+#define swap16_multi(v, n) do { \
__size_t __swap16_multi_n = (n); \
__uint16_t *__swap16_multi_v = (v); \
\
@@ -153,168 +80,43 @@
} \
} while (0)
-#if __BSD_VISIBLE
-#define swap16 __swap16
-#define swap32 __swap32
-#define swap64 __swap64
-#define swap16_multi __swap16_multi
-
-__BEGIN_DECLS
-__uint64_t htobe64(__uint64_t);
-__uint32_t htobe32(__uint32_t);
-__uint16_t htobe16(__uint16_t);
-__uint64_t betoh64(__uint64_t);
-__uint32_t betoh32(__uint32_t);
-__uint16_t betoh16(__uint16_t);
-
-__uint64_t htole64(__uint64_t);
-__uint32_t htole32(__uint32_t);
-__uint16_t htole16(__uint16_t);
-__uint64_t letoh64(__uint64_t);
-__uint32_t letoh32(__uint32_t);
-__uint16_t letoh16(__uint16_t);
-__END_DECLS
-#endif /* __BSD_VISIBLE */
-
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-
-/* Can be overridden by machine/endian.h before inclusion of this file. */
-#ifndef _QUAD_HIGHWORD
-#define _QUAD_HIGHWORD 1
-#endif
-#ifndef _QUAD_LOWWORD
-#define _QUAD_LOWWORD 0
-#endif
-
-#if __BSD_VISIBLE
-#define htobe16 __swap16
-#define htobe32 __swap32
-#define htobe64 __swap64
-#define betoh16 __swap16
-#define betoh32 __swap32
-#define betoh64 __swap64
-
-#define htole16(x) ((__uint16_t)(x))
-#define htole32(x) ((__uint32_t)(x))
-#define htole64(x) ((__uint64_t)(x))
-#define letoh16(x) ((__uint16_t)(x))
-#define letoh32(x) ((__uint32_t)(x))
-#define letoh64(x) ((__uint64_t)(x))
-#endif /* __BSD_VISIBLE */
-
-#define htons(x) __swap16(x)
-#define htonl(x) __swap32(x)
-#define ntohs(x) __swap16(x)
-#define ntohl(x) __swap32(x)
-
-#ifdef _KERNEL
-
-#ifdef MD_SWAPIO
-
-#define bemtoh16(_x) __mswap16(_x)
-#define bemtoh32(_x) __mswap32(_x)
-#define bemtoh64(_x) __mswap64(_x)
-
-#define htobem16(_x, _v) __swapm16((_x), (_v))
-#define htobem32(_x, _v) __swapm32((_x), (_v))
-#define htobem64(_x, _v) __swapm64((_x), (_v))
-
-#else /* MD_SWAPIO */
-
-#define bemtoh16(_x) htobe16(*(__uint16_t *)(_x))
-#define bemtoh32(_x) htobe32(*(__uint32_t *)(_x))
-#define bemtoh64(_x) htobe64(*(__uint64_t *)(_x))
-
-#define htobem16(_x, _v) (*(__uint16_t *)(_x) = htobe16(_v))
-#define htobem32(_x, _v) (*(__uint32_t *)(_x) = htobe32(_v))
-#define htobem64(_x, _v) (*(__uint64_t *)(_x) = htobe64(_v))
-
-#endif /* MD_SWAPIO */
-
-#define lemtoh16(_x) (*(__uint16_t *)(_x))
-#define lemtoh32(_x) (*(__uint32_t *)(_x))
-#define lemtoh64(_x) (*(__uint64_t *)(_x))
-
-#define htolem16(_x, _v) (*(__uint16_t *)(_x) = (__uint16_t)(_v))
-#define htolem32(_x, _v) (*(__uint32_t *)(_x) = (__uint32_t)(_v))
-#define htolem64(_x, _v) (*(__uint64_t *)(_x) = (__uint64_t)(_v))
-
-#endif /* _KERNEL */
-
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
-
-#if _BYTE_ORDER == _BIG_ENDIAN
-
-/* Can be overridden by machine/endian.h before inclusion of this file. */
-#ifndef _QUAD_HIGHWORD
-#define _QUAD_HIGHWORD 0
-#endif
-#ifndef _QUAD_LOWWORD
-#define _QUAD_LOWWORD 1
+/* original BSD names */
+#define betoh16(x) __htobe16(x)
+#define betoh32(x) __htobe32(x)
+#define betoh64(x) __htobe64(x)
+#define letoh16(x) __htole16(x)
+#define letoh32(x) __htole32(x)
+#define letoh64(x) __htole64(x)
+
+#ifndef htons
+/* these were exposed here before */
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
#endif
-#if __BSD_VISIBLE
-#define htole16 __swap16
-#define htole32 __swap32
-#define htole64 __swap64
-#define letoh16 __swap16
-#define letoh32 __swap32
-#define letoh64 __swap64
-
-#define htobe16(x) ((__uint16_t)(x))
-#define htobe32(x) ((__uint32_t)(x))
-#define htobe64(x) ((__uint64_t)(x))
-#define betoh16(x) ((__uint16_t)(x))
-#define betoh32(x) ((__uint32_t)(x))
-#define betoh64(x) ((__uint64_t)(x))
-#endif /* __BSD_VISIBLE */
-
-#define htons(x) ((__uint16_t)(x))
-#define htonl(x) ((__uint32_t)(x))
-#define ntohs(x) ((__uint16_t)(x))
-#define ntohl(x) ((__uint32_t)(x))
-
-#ifdef _KERNEL
-
-#ifdef MD_SWAPIO
-
-#define lemtoh16(_x) __mswap16(_x)
-#define lemtoh32(_x) __mswap32(_x)
-#define lemtoh64(_x) __mswap64(_x)
-
-#define htolem16(_x, _v) __swapm16((_x), (_v))
-#define htolem32(_x, _v) __swapm32((_x), (_v))
-#define htolem64(_x, _v) __swapm64((_x), (_v))
-
-#else /* MD_SWAPIO */
-
-#define lemtoh16(_x) htole16(*(__uint16_t *)(_x))
-#define lemtoh32(_x) htole32(*(__uint32_t *)(_x))
-#define lemtoh64(_x) htole64(*(__uint64_t *)(_x))
-
-#define htolem16(_x, _v) (*(__uint16_t *)(_x) = htole16(_v))
-#define htolem32(_x, _v) (*(__uint32_t *)(_x) = htole32(_v))
-#define htolem64(_x, _v) (*(__uint64_t *)(_x) = htole64(_v))
-
-#endif /* MD_SWAPIO */
-
-#define bemtoh16(_x) (*(__uint16_t *)(_x))
-#define bemtoh32(_x) (*(__uint32_t *)(_x))
-#define bemtoh64(_x) (*(__uint64_t *)(_x))
-
-#define htobem16(_x, _v) (*(__uint16_t *)(_x) = (__uint16_t)(_v))
-#define htobem32(_x, _v) (*(__uint32_t *)(_x) = (__uint32_t)(_v))
-#define htobem64(_x, _v) (*(__uint64_t *)(_x) = (__uint64_t)(_v))
-
-#endif /* _KERNEL */
-
-#endif /* _BYTE_ORDER == _BIG_ENDIAN */
-
-#if __BSD_VISIBLE
+/* ancient stuff */
#define NTOHL(x) (x) = ntohl((u_int32_t)(x))
#define NTOHS(x) (x) = ntohs((u_int16_t)(x))
#define HTONL(x) (x) = htonl((u_int32_t)(x))
#define HTONS(x) (x) = htons((u_int16_t)(x))
-#endif
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+/* to/from memory conversions */
+#define bemtoh16 __bemtoh16
+#define bemtoh32 __bemtoh32
+#define bemtoh64 __bemtoh64
+#define htobem16 __htobem16
+#define htobem32 __htobem32
+#define htobem64 __htobem64
+#define lemtoh16 __lemtoh16
+#define lemtoh32 __lemtoh32
+#define lemtoh64 __lemtoh64
+#define htolem16 __htolem16
+#define htolem32 __htolem32
+#define htolem64 __htolem64
+#endif /* _KERNEL */
#endif /* _SYS_ENDIAN_H_ */
diff --git a/sys/sys/types.h b/sys/sys/types.h
index f3a0e73505f..a2e9962693e 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: types.h,v 1.40 2014/03/11 19:45:28 guenther Exp $ */
+/* $OpenBSD: types.h,v 1.41 2014/07/12 16:25:08 guenther Exp $ */
/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
/*-
@@ -40,8 +40,12 @@
#ifndef _SYS_TYPES_H_
#define _SYS_TYPES_H_
-#include <sys/_types.h>
-#include <machine/endian.h>
+#include <sys/cdefs.h>
+#if __BSD_VISIBLE
+#include <sys/endian.h>
+#else
+#include <sys/_endian.h>
+#endif
#if __BSD_VISIBLE
typedef unsigned char u_char;