]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/_endian.h
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved.
33 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
35 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
37 * This file contains Original Code and/or Modifications of Original Code
38 * as defined in and that are subject to the Apple Public Source License
39 * Version 2.0 (the 'License'). You may not use this file except in
40 * compliance with the License. The rights granted to you under the
41 * License may not be used to create, or enable the creation or
42 * redistribution of, unlawful or unlicensed copies of an Apple operating
43 * system, or to circumvent, violate, or enable the circumvention or
44 * violation of, any terms of an Apple operating system software license
47 * Please obtain a copy of the License at
48 * http://www.opensource.apple.com/apsl/ and read it before using this
51 * The Original Code and all software distributed under the License are
52 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
53 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
54 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
55 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
56 * Please see the License for the specific language governing rights and
57 * limitations under the License.
59 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
62 * Copyright (c) 1987, 1991, 1993
63 * The Regents of the University of California. All rights reserved.
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in the
72 * documentation and/or other materials provided with the distribution.
73 * 3. All advertising materials mentioning features or use of this software
74 * must display the following acknowledgement:
75 * This product includes software developed by the University of
76 * California, Berkeley and its contributors.
77 * 4. Neither the name of the University nor the names of its contributors
78 * may be used to endorse or promote products derived from this software
79 * without specific prior written permission.
81 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
82 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 #ifndef _SYS__ENDIAN_H_
95 #define _SYS__ENDIAN_H_
97 #include <sys/cdefs.h>
100 * Macros for network/external number representation conversion.
102 #if !defined(__ASSEMBLER__)
105 #include <libkern/OSByteOrder.h>
108 uint16_t ntohs(uint16_t);
109 uint16_t htons(uint16_t);
110 uint32_t ntohl(uint32_t);
111 uint32_t htonl(uint32_t);
113 #endif /* !defined(__ASSEMBLER__) */
115 #define ntohs(x) OSSwapBigToHostInt16(x)
116 #define htons(x) OSSwapHostToBigInt16(x)
118 #define ntohl(x) OSSwapBigToHostInt32(x)
119 #define htonl(x) OSSwapHostToBigInt32(x)
121 #if defined(KERNEL) || !defined(_POSIX_C_SOURCE)
122 #define NTOHL(x) (x) = ntohl((u_long)x)
123 #define NTOHS(x) (x) = ntohs((u_short)x)
124 #define HTONL(x) (x) = htonl((u_long)x)
125 #define HTONS(x) (x) = htons((u_short)x)
126 #endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
127 #endif /* !_SYS__ENDIAN_H_ */