]>
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_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved.
25 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
27 * @APPLE_LICENSE_HEADER_START@
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.
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
43 * @APPLE_LICENSE_HEADER_END@
46 * Copyright (c) 1987, 1991, 1993
47 * The Regents of the University of California. All rights reserved.
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
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.
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
78 #ifndef _SYS__ENDIAN_H_
79 #define _SYS__ENDIAN_H_
81 #include <sys/cdefs.h>
84 * Macros for network/external number representation conversion.
86 #if !defined(__ASSEMBLER__)
89 #include <libkern/OSByteOrder.h>
92 uint16_t ntohs(uint16_t);
93 uint16_t htons(uint16_t);
94 uint32_t ntohl(uint32_t);
95 uint32_t htonl(uint32_t);
97 #endif /* !defined(__ASSEMBLER__) */
99 #define ntohs(x) OSSwapBigToHostInt16(x)
100 #define htons(x) OSSwapHostToBigInt16(x)
102 #define ntohl(x) OSSwapBigToHostInt32(x)
103 #define htonl(x) OSSwapHostToBigInt32(x)
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_ */