]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/_endian.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / sys / _endian.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved.
25 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
26 *
27 * @APPLE_LICENSE_HEADER_START@
28 *
29 * The contents of this file constitute Original Code as defined in and
30 * are subject to the Apple Public Source License Version 1.1 (the
31 * "License"). You may not use this file except in compliance with the
32 * License. Please obtain a copy of the License at
33 * http://www.apple.com/publicsource and read it before using this file.
34 *
35 * This Original Code and all software distributed under the License are
36 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
37 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
38 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
39 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
40 * License for the specific language governing rights and limitations
41 * under the License.
42 *
43 * @APPLE_LICENSE_HEADER_END@
44 */
45 /*
46 * Copyright (c) 1987, 1991, 1993
47 * The Regents of the University of California. All rights reserved.
48 *
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
51 * are met:
52 * 1. Redistributions of source code must retain the above copyright
53 * notice, this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright
55 * notice, this list of conditions and the following disclaimer in the
56 * documentation and/or other materials provided with the distribution.
57 * 3. All advertising materials mentioning features or use of this software
58 * must display the following acknowledgement:
59 * This product includes software developed by the University of
60 * California, Berkeley and its contributors.
61 * 4. Neither the name of the University nor the names of its contributors
62 * may be used to endorse or promote products derived from this software
63 * without specific prior written permission.
64 *
65 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 * SUCH DAMAGE.
76 */
77
78 #ifndef _SYS__ENDIAN_H_
79 #define _SYS__ENDIAN_H_
80
81 #include <sys/cdefs.h>
82
83 /*
84 * Macros for network/external number representation conversion.
85 */
86 #if !defined(__ASSEMBLER__)
87
88 #include <stdint.h>
89 #include <libkern/OSByteOrder.h>
90
91 __BEGIN_DECLS
92 uint16_t ntohs(uint16_t);
93 uint16_t htons(uint16_t);
94 uint32_t ntohl(uint32_t);
95 uint32_t htonl(uint32_t);
96 __END_DECLS
97 #endif /* !defined(__ASSEMBLER__) */
98
99 #define ntohs(x) OSSwapBigToHostInt16(x)
100 #define htons(x) OSSwapHostToBigInt16(x)
101
102 #define ntohl(x) OSSwapBigToHostInt32(x)
103 #define htonl(x) OSSwapHostToBigInt32(x)
104
105 #if defined(KERNEL) || !defined(_POSIX_C_SOURCE)
106 #define NTOHL(x) (x) = ntohl((u_long)x)
107 #define NTOHS(x) (x) = ntohs((u_short)x)
108 #define HTONL(x) (x) = htonl((u_long)x)
109 #define HTONS(x) (x) = htons((u_short)x)
110 #endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
111 #endif /* !_SYS__ENDIAN_H_ */