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