libmtp  1.1.6
gphoto2-endian.h
1 /* This file is generated automatically by configure */
2 /* It is valid only for the system type x86_64-unknown-openbsd5.6 */
3 
4 #ifndef __BYTEORDER_H
5 #define __BYTEORDER_H
6 
7 /* extended byte swapping macros are already available */
8 #include <machine/endian.h>
9 
10 /* Use these as generic byteswapping macros on this little endian system */
11 #define swap16(x) ntohs(x)
12 #define swap32(x) ntohl(x)
13 /* No optimized 64 bit byte swapping macro is available */
14 #define swap64(x) ((uint64_t)(((uint64_t)(x) << 56) & 0xff00000000000000ULL | \
15  ((uint64_t)(x) << 40) & 0x00ff000000000000ULL | \
16  ((uint64_t)(x) << 24) & 0x0000ff0000000000ULL | \
17  ((uint64_t)(x) << 8) & 0x000000ff00000000ULL | \
18  ((x) >> 8) & 0x00000000ff000000ULL | \
19  ((x) >> 24) & 0x0000000000ff0000ULL | \
20  ((x) >> 40) & 0x000000000000ff00ULL | \
21  ((x) >> 56) & 0x00000000000000ffULL))
22 
23 /* Define the C99 standard length-specific integer types */
24 #include <_stdint.h>
25 
26 /* Here are some macros to create integers from a byte array */
27 /* These are used to get and put integers from/into a uint8_t array */
28 /* with a specific endianness. This is the most portable way to generate */
29 /* and read messages to a network or serial device. Each member of a */
30 /* packet structure must be handled separately. */
31 
32 /* Non-optimized but portable macros */
33 #define be16atoh(x) ((uint16_t)(((x)[0]<<8)|(x)[1]))
34 #define be32atoh(x) ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
35 #define be64atoh_x(x,off,shift) (((uint64_t)((x)[off]))<<shift)
36 #define be64atoh(x) ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \
37  be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
38 #define le16atoh(x) ((uint16_t)(((x)[1]<<8)|(x)[0]))
39 #define le32atoh(x) ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
40 #define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
41 #define le64atoh(x) ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \
42  le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
43 
44 #define htobe16a(a,x) (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
45 #define htobe32a(a,x) (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \
46  (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
47 #define htobe64a(a,x) (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \
48  (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \
49  (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \
50  (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
51 #define htole16a(a,x) (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
52 #define htole32a(a,x) (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
53  (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
54 #define htole64a(a,x) (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \
55  (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \
56  (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
57  (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
58 
59 #endif /*__BYTEORDER_H*/