]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/_endian.h
3caddc156d9f2f885943c38d582bb62b0162bbee
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved.
26 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
28 * @APPLE_LICENSE_HEADER_START@
30 * This file contains Original Code and/or Modifications of Original Code
31 * as defined in and that are subject to the Apple Public Source License
32 * Version 2.0 (the 'License'). You may not use this file except in
33 * compliance with the License. Please obtain a copy of the License at
34 * http://www.opensource.apple.com/apsl/ and read it before using this
37 * The Original Code and all software distributed under the License are
38 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
39 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
40 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
41 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
42 * Please see the License for the specific language governing rights and
43 * limitations under the License.
45 * @APPLE_LICENSE_HEADER_END@
48 * Copyright (c) 1987, 1991, 1993
49 * The Regents of the University of California. All rights reserved.
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
54 * 1. Redistributions of source code must retain the above copyright
55 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in the
58 * documentation and/or other materials provided with the distribution.
59 * 3. All advertising materials mentioning features or use of this software
60 * must display the following acknowledgement:
61 * This product includes software developed by the University of
62 * California, Berkeley and its contributors.
63 * 4. Neither the name of the University nor the names of its contributors
64 * may be used to endorse or promote products derived from this software
65 * without specific prior written permission.
67 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80 #ifndef _SYS__ENDIAN_H_
81 #define _SYS__ENDIAN_H_
83 #include <sys/cdefs.h>
86 * Macros for network/external number representation conversion.
88 #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN && !defined(lint)
94 #if defined(KERNEL) || !defined(_POSIX_C_SOURCE)
99 #endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
103 #if !defined(__ASSEMBLER__)
106 #include <machine/byte_order.h>
109 uint16_t ntohs(uint16_t);
110 uint16_t htons(uint16_t);
111 uint32_t ntohl(uint32_t);
112 uint32_t htonl(uint32_t);
114 #endif /* !defined(__ASSEMBLER__) */
116 #define ntohs(x) NXSwapBigShortToHost(x)
117 #define htons(x) NXSwapHostShortToBig(x)
119 #if defined(__LP64__)
120 #define ntohl(x) NXSwapBigIntToHost(x)
121 #define htonl(x) NXSwapHostIntToBig(x)
123 #define ntohl(x) NXSwapBigLongToHost(x)
124 #define htonl(x) NXSwapHostLongToBig(x)
125 #endif /* defined(__LP64__) */
127 #if defined(KERNEL) || !defined(_POSIX_C_SOURCE)
128 #define NTOHL(x) (x) = ntohl((u_long)x)
129 #define NTOHS(x) (x) = ntohs((u_short)x)
130 #define HTONL(x) (x) = htonl((u_long)x)
131 #define HTONS(x) (x) = htons((u_short)x)
132 #endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
133 #endif /* __DARWIN_BYTE_ORDER != __DARWIN_BIG_ENDIAN || defined(lint) */
134 #endif /* !_SYS__ENDIAN_H_ */