xref: /illumos-gate/usr/src/head/endian.h (revision 58e78d166bd2b5a9dda31250b8e8bad7c7548c0e)
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 #if	defined(_LITTLE_ENDIAN)
35 #define	__BYTE_ORDER	LITTLE_ENDIAN
36 #elif	defined(_BIG_ENDIAN)
37 #define	__BYTE_ORDER	BIG_ENDIAN
38 #else
39 #error	"Unknown byte order"
40 #endif	/* _LITTLE_ENDIAN */
41 
42 #define	LITTLE_ENDIAN	__LITTLE_ENDIAN
43 #define	BIG_ENDIAN	__BIG_ENDIAN
44 #define	BYTE_ORDER	__BYTE_ORDER
45 
46 extern uint16_t htobe16(uint16_t);
47 extern uint32_t htobe32(uint32_t);
48 extern uint64_t htobe64(uint64_t);
49 
50 extern uint16_t htole16(uint16_t);
51 extern uint32_t htole32(uint32_t);
52 extern uint64_t htole64(uint64_t);
53 
54 /* Supply both the old and new BSD names */
55 extern uint16_t betoh16(uint16_t);
56 extern uint16_t letoh16(uint16_t);
57 extern uint16_t be16toh(uint16_t);
58 extern uint16_t le16toh(uint16_t);
59 
60 extern uint32_t betoh32(uint32_t);
61 extern uint32_t letoh32(uint32_t);
62 extern uint32_t be32toh(uint32_t);
63 extern uint32_t le32toh(uint32_t);
64 
65 extern uint64_t betoh64(uint64_t);
66 extern uint64_t letoh64(uint64_t);
67 extern uint64_t be64toh(uint64_t);
68 extern uint64_t le64toh(uint64_t);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* _ENDIAN_H */
75