X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8f6c56a50524aa785f7e596d52dddfb331e18961..060df5ea7c632b1ac8cc8aac1fb59758165c2084:/bsd/sys/_endian.h diff --git a/bsd/sys/_endian.h b/bsd/sys/_endian.h index 3aa34f4c8..3fb0f062f 100644 --- a/bsd/sys/_endian.h +++ b/bsd/sys/_endian.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -95,50 +95,45 @@ /* * 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) */ +#if defined(lint) -#else - -#if !defined(__ASSEMBLER__) - -#include -#include - __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) +#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 NTOHL(x) (x) +#define NTOHS(x) (x) +#define HTONL(x) (x) +#define HTONS(x) (x) +#endif /* defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */ + +#else /* __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN */ + +#include + +#define ntohs(x) __DARWIN_OSSwapInt16(x) +#define htons(x) __DARWIN_OSSwapInt16(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__) */ +#define ntohl(x) __DARWIN_OSSwapInt32(x) +#define htonl(x) __DARWIN_OSSwapInt32(x) -#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) */ +#if defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) +#define NTOHL(x) (x) = ntohl((__uint32_t)x) +#define NTOHS(x) (x) = ntohs((__uint16_t)x) +#define HTONL(x) (x) = htonl((__uint32_t)x) +#define HTONS(x) (x) = htons((__uint16_t)x) +#endif /* defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */ +#endif /* __DARWIN_BYTE_ORDER */ #endif /* !_SYS__ENDIAN_H_ */