xref: /titanic_44/usr/src/head/endian.h (revision a91a4784a003412061074cc4abccefbbfe2fa170)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Joyent, Inc.
14  */
15 
16 #ifndef _ENDIAN_H
17 #define	_ENDIAN_H
18 
19 /*
20  * Endian conversion routines, see endian(3C)
21  */
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <sys/isa_defs.h>
28 #include <inttypes.h>
29 
30 #define	LITTLE_ENDIAN	1234
31 #define	BIG_ENDIAN	4321
32 #define	PDP_ENDIAN	3412
33 
34 #ifdef	_LITTLE_ENDIAN
35 #define	BYTE_ORDER	LITTLE_ENDIAN
36 #elif	_BIG_ENDIAN
37 #define	BYTE_ORDER	BIG_ENDIAN
38 #else
39 #error	"Unknown byte order"
40 #endif	/* _LITTLE_ENDIAN */
41 
42 extern uint16_t htobe16(uint16_t);
43 extern uint32_t htobe32(uint32_t);
44 extern uint64_t htobe64(uint64_t);
45 
46 extern uint16_t htole16(uint16_t);
47 extern uint32_t htole32(uint32_t);
48 extern uint64_t htole64(uint64_t);
49 
50 /* Supply both the old and new BSD names */
51 extern uint16_t betoh16(uint16_t);
52 extern uint16_t letoh16(uint16_t);
53 extern uint16_t be16toh(uint16_t);
54 extern uint16_t le16toh(uint16_t);
55 
56 extern uint32_t betoh32(uint32_t);
57 extern uint32_t letoh32(uint32_t);
58 extern uint32_t be32toh(uint32_t);
59 extern uint32_t le32toh(uint32_t);
60 
61 extern uint64_t betoh64(uint64_t);
62 extern uint64_t letoh64(uint64_t);
63 extern uint64_t be64toh(uint64_t);
64 extern uint64_t le64toh(uint64_t);
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif /* _ENDIAN_H */
71