]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/_endian.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / sys / _endian.h
CommitLineData
ccc36f2f 1/*
8ad349bb 2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
91447636 3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
91447636 5 *
8ad349bb
A
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
91447636
A
29 */
30
31/*
32 * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved.
ccc36f2f
A
33 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
34 *
8ad349bb 35 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
ccc36f2f 36 *
8ad349bb
A
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
45 * agreement.
46 *
47 * Please obtain a copy of the License at
48 * http://www.opensource.apple.com/apsl/ and read it before using this
49 * file.
50 *
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.
58 *
59 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
ccc36f2f 60 */
ccc36f2f 61/*
91447636 62 * Copyright (c) 1987, 1991, 1993
ccc36f2f
A
63 * The Regents of the University of California. All rights reserved.
64 *
ccc36f2f
A
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
67 * are met:
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.
80 *
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
91 * SUCH DAMAGE.
ccc36f2f 92 */
ccc36f2f 93
91447636
A
94#ifndef _SYS__ENDIAN_H_
95#define _SYS__ENDIAN_H_
96
97#include <sys/cdefs.h>
ccc36f2f 98
ccc36f2f 99/*
91447636 100 * Macros for network/external number representation conversion.
ccc36f2f 101 */
8ad349bb
A
102#if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN && !defined(lint)
103#define ntohl(x) (x)
104#define ntohs(x) (x)
105#define htonl(x) (x)
106#define htons(x) (x)
107
108#if defined(KERNEL) || !defined(_POSIX_C_SOURCE)
109#define NTOHL(x) (x)
110#define NTOHS(x) (x)
111#define HTONL(x) (x)
112#define HTONS(x) (x)
113#endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
114
115#else
116
91447636 117#if !defined(__ASSEMBLER__)
ccc36f2f 118
91447636 119#include <stdint.h>
8ad349bb 120#include <machine/byte_order.h>
91447636 121
ccc36f2f 122__BEGIN_DECLS
91447636
A
123uint16_t ntohs(uint16_t);
124uint16_t htons(uint16_t);
125uint32_t ntohl(uint32_t);
126uint32_t htonl(uint32_t);
ccc36f2f 127__END_DECLS
91447636
A
128#endif /* !defined(__ASSEMBLER__) */
129
8ad349bb
A
130#define ntohs(x) NXSwapBigShortToHost(x)
131#define htons(x) NXSwapHostShortToBig(x)
ccc36f2f 132
8ad349bb
A
133#if defined(__LP64__)
134#define ntohl(x) NXSwapBigIntToHost(x)
135#define htonl(x) NXSwapHostIntToBig(x)
136#else
137#define ntohl(x) NXSwapBigLongToHost(x)
138#define htonl(x) NXSwapHostLongToBig(x)
139#endif /* defined(__LP64__) */
ccc36f2f 140
91447636
A
141#if defined(KERNEL) || !defined(_POSIX_C_SOURCE)
142#define NTOHL(x) (x) = ntohl((u_long)x)
143#define NTOHS(x) (x) = ntohs((u_short)x)
144#define HTONL(x) (x) = htonl((u_long)x)
145#define HTONS(x) (x) = htons((u_short)x)
146#endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */
8ad349bb 147#endif /* __DARWIN_BYTE_ORDER != __DARWIN_BIG_ENDIAN || defined(lint) */
91447636 148#endif /* !_SYS__ENDIAN_H_ */