]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/sys/_endian.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / _endian.h
index 3aa34f4c844dd805d34c9ad587a9e42288297cf3..79fa016695bc0214e9970eeb54a1f6116ebdd223 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004, 2006 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * unlawful or unlicensed copies of an Apple operating system, or to
  * circumvent, violate, or enable the circumvention or violation of, any
  * terms of an Apple operating system software license agreement.
- * 
+ *
  * Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -22,7 +22,7 @@
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
@@ -31,7 +31,7 @@
  * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * unlawful or unlicensed copies of an Apple operating system, or to
  * circumvent, violate, or enable the circumvention or violation of, any
  * terms of an Apple operating system software license agreement.
- * 
+ *
  * Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -51,7 +51,7 @@
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  */
 
 #ifndef _SYS__ENDIAN_H_
-#define        _SYS__ENDIAN_H_
+#define _SYS__ENDIAN_H_
 
 #include <sys/cdefs.h>
 
 /*
  * Macros for network/external number representation conversion.
  */
-#if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN && !defined(lint)
-#define        ntohl(x)        (x)
-#define        ntohs(x)        (x)
-#define        htonl(x)        (x)
-#define        htons(x)        (x)
-
-#if    defined(KERNEL) || !defined(_POSIX_C_SOURCE)
-#define        NTOHL(x)        (x)
-#define        NTOHS(x)        (x)
-#define        HTONL(x)        (x)
-#define        HTONS(x)        (x)
-#endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
-
-#else
-
-#if !defined(__ASSEMBLER__) 
-
-#include <stdint.h>
-#include <machine/byte_order.h>
+
+#if defined(lint)
+
 __BEGIN_DECLS
-uint16_t       ntohs(uint16_t);
-uint16_t       htons(uint16_t);
-uint32_t       ntohl(uint32_t);
-uint32_t       htonl(uint32_t);
+__uint16_t      ntohs(__uint16_t);
+__uint16_t      htons(__uint16_t);
+__uint32_t      ntohl(__uint32_t);
+__uint32_t      htonl(__uint32_t);
 __END_DECLS
-#endif /* !defined(__ASSEMBLER__) */
-
-#define ntohs(x)       NXSwapBigShortToHost(x)
-#define htons(x)       NXSwapHostShortToBig(x)
-
-#if defined(__LP64__)
-#define ntohl(x)       NXSwapBigIntToHost(x)
-#define htonl(x)       NXSwapHostIntToBig(x)
-#else 
-#define ntohl(x)       NXSwapBigLongToHost(x)
-#define htonl(x)       NXSwapHostLongToBig(x)
-#endif /* defined(__LP64__) */
-
-#if    defined(KERNEL) || !defined(_POSIX_C_SOURCE)
-#define        NTOHL(x)        (x) = ntohl((u_long)x)
-#define        NTOHS(x)        (x) = ntohs((u_short)x)
-#define        HTONL(x)        (x) = htonl((u_long)x)
-#define        HTONS(x)        (x) = htons((u_short)x)
-#endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
-#endif /* __DARWIN_BYTE_ORDER != __DARWIN_BIG_ENDIAN || defined(lint) */ 
+
+#elif __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
+
+#define ntohl(x)        ((__uint32_t)(x))
+#define ntohs(x)        ((__uint16_t)(x))
+#define htonl(x)        ((__uint32_t)(x))
+#define htons(x)        ((__uint16_t)(x))
+
+#if     defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
+
+#define ntohll(x)       ((__uint64_t)(x))
+#define htonll(x)       ((__uint64_t)(x))
+
+#define NTOHL(x)        (x)
+#define NTOHS(x)        (x)
+#define NTOHLL(x)       (x)
+#define HTONL(x)        (x)
+#define HTONS(x)        (x)
+#define HTONLL(x)       (x)
+#endif /* defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */
+
+#else   /* __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN */
+
+#ifndef DRIVERKIT
+#include <libkern/_OSByteOrder.h>
+
+#define ntohs(x)        __DARWIN_OSSwapInt16(x)
+#define htons(x)        __DARWIN_OSSwapInt16(x)
+
+#define ntohl(x)        __DARWIN_OSSwapInt32(x)
+#define htonl(x)        __DARWIN_OSSwapInt32(x)
+#else /* DRIVERKIT */
+#define ntohs(x)        ((__uint16_t)__builtin_bswap16((__uint16_t)(x)))
+#define htons(x)        ((__uint16_t)__builtin_bswap16((__uint16_t)(x)))
+
+#define ntohl(x)        ((__uint32_t)__builtin_bswap32((__uint32_t)(x)))
+#define htonl(x)        ((__uint32_t)__builtin_bswap32((__uint32_t)(x)))
+#endif /* DRIVERKIT */
+
+#if     defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
+
+#ifndef DRIVERKIT
+#define ntohll(x)       __DARWIN_OSSwapInt64(x)
+#define htonll(x)       __DARWIN_OSSwapInt64(x)
+#else /* DRIVERKIT */
+#define ntohll(x)       ((__uint64_t)__builtin_bswap64((__uint64_t)(x)))
+#define htonll(x)       ((__uint64_t)__builtin_bswap64((__uint64_t)(x)))
+#endif /* DRIVERKIT */
+
+#define NTOHL(x)        (x) = ntohl((__uint32_t)x)
+#define NTOHS(x)        (x) = ntohs((__uint16_t)x)
+#define NTOHLL(x)       (x) = ntohll((__uint64_t)x)
+#define HTONL(x)        (x) = htonl((__uint32_t)x)
+#define HTONS(x)        (x) = htons((__uint16_t)x)
+#define HTONLL(x)       (x) = htonll((__uint64_t)x)
+#endif /* defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */
+#endif /* __DARWIN_BYTE_ORDER */
 #endif /* !_SYS__ENDIAN_H_ */