libmtp  1.1.6
gphoto2-endian.h
1 /* This file is generated automatically by configure */
2 /* It is valid only for the system type arm-unknown-openbsd5.5 */
3 
4 #ifndef __BYTEORDER_H
5 #define __BYTEORDER_H
6 
7 /* ntohl and relatives live here */
8 #include <arpa/inet.h>
9 
10 /* swap32 and swap16 are defined in machine/endian.h */
11 
12 /* The byte swapping macros have the form: */
13 /* EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
14 /* le (little-endian), NN is 16 or 32 (number of bits) and a, */
15 /* if present, indicates that the endian side is a pointer to an */
16 /* array of uint8_t bytes instead of an integer of the specified length. */
17 /* h refers to the host's ordering method. */
18 
19 /* So, to convert a 32-bit integer stored in a buffer in little-endian */
20 /* format into a uint32_t usable on this machine, you could use: */
21 /* uint32_t value = le32atoh(&buf[3]); */
22 /* To put that value back into the buffer, you could use: */
23 /* htole32a(&buf[3], value); */
24 
25 /* Define aliases for the standard byte swapping macros */
26 /* Arguments to these macros must be properly aligned on natural word */
27 /* boundaries in order to work properly on all architectures */
28 #ifndef htobe16
29 # define htobe16(x) htons(x)
30 #endif
31 #ifndef htobe32
32 # define htobe32(x) htonl(x)
33 #endif
34 #ifndef be16toh
35 # define be16toh(x) ntohs(x)
36 #endif
37 #ifndef be32toh
38 # define be32toh(x) ntohl(x)
39 #endif
40 
41 #define HTOBE16(x) (x) = htobe16(x)
42 #define HTOBE32(x) (x) = htobe32(x)
43 #define BE32TOH(x) (x) = be32toh(x)
44 #define BE16TOH(x) (x) = be16toh(x)
45 
46 /* On little endian machines, these macros are null */
47 #ifndef htole16
48 # define htole16(x) (x)
49 #endif
50 #ifndef htole32
51 # define htole32(x) (x)
52 #endif
53 #ifndef htole64
54 # define htole64(x) (x)
55 #endif
56 #ifndef le16toh
57 # define le16toh(x) (x)
58 #endif
59 #ifndef le32toh
60 # define le32toh(x) (x)
61 #endif
62 #ifndef le64toh
63 # define le64toh(x) (x)
64 #endif
65 
66 #define HTOLE16(x) (void) (x)
67 #define HTOLE32(x) (void) (x)
68 #define HTOLE64(x) (void) (x)
69 #define LE16TOH(x) (void) (x)
70 #define LE32TOH(x) (void) (x)
71 #define LE64TOH(x) (void) (x)
72 
73 /* These don't have standard aliases */
74 #ifndef htobe64
75 # define htobe64(x) swap64(x)
76 #endif
77 #ifndef be64toh
78 # define be64toh(x) swap64(x)
79 #endif
80 
81 #define HTOBE64(x) (x) = htobe64(x)
82 #define BE64TOH(x) (x) = be64toh(x)
83 
84 /* Define the C99 standard length-specific integer types */
85 #include <_stdint.h>
86 
87 /* Here are some macros to create integers from a byte array */
88 /* These are used to get and put integers from/into a uint8_t array */
89 /* with a specific endianness. This is the most portable way to generate */
90 /* and read messages to a network or serial device. Each member of a */
91 /* packet structure must be handled separately. */
92 
93 /* Non-optimized but portable macros */
94 #define be16atoh(x) ((uint16_t)(((x)[0]<<8)|(x)[1]))
95 #define be32atoh(x) ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
96 #define be64atoh_x(x,off,shift) (((uint64_t)((x)[off]))<<shift)
97 #define be64atoh(x) ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \
98  be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
99 #define le16atoh(x) ((uint16_t)(((x)[1]<<8)|(x)[0]))
100 #define le32atoh(x) ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
101 #define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
102 #define le64atoh(x) ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \
103  le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
104 
105 #define htobe16a(a,x) (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
106 #define htobe32a(a,x) (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \
107  (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
108 #define htobe64a(a,x) (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \
109  (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \
110  (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \
111  (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
112 #define htole16a(a,x) (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
113 #define htole32a(a,x) (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
114  (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
115 #define htole64a(a,x) (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \
116  (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \
117  (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
118  (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
119 
120 #endif /*__BYTEORDER_H*/