libgphoto2 photo camera library (libgphoto2) API 2.5.31
gphoto2-endian.h
1/* This file is generated automatically by configure */
2/* It is valid only for the system type i686-w64-mingw32 */
3
4#ifndef GP_BYTEORDER_H
5#define GP_BYTEORDER_H
6
7/* Use these as generic byteswapping macros on this little endian system */
8/* on windows we might not have ntohs / ntohl without including winsock.dll,
9 * so use generic macros */
10#ifdef __HAVE_NTOHL
11# define swap16(x) htons(x)
12# define swap32(x) htonl(x)
13#else
14# define swap16(x) ((uint16_t)(((x) << 8) | ((uint16_t)(x) >> 8)))
15# define swap32(x) ((uint32_t)((((uint32_t)(x) << 24) & 0xff000000UL) | \
16 (((uint32_t)(x) << 8) & 0x00ff0000UL) | \
17 (((x) >> 8) & 0x0000ff00UL) | \
18 (((x) >> 24) & 0x000000ffUL)))
19#endif
20/* No optimized 64 bit byte swapping macro is available */
21#define swap64(x) ((uint64_t)((((uint64_t)(x) << 56) & 0xff00000000000000ULL) | \
22 (((uint64_t)(x) << 40) & 0x00ff000000000000ULL) | \
23 (((uint64_t)(x) << 24) & 0x0000ff0000000000ULL) | \
24 (((uint64_t)(x) << 8) & 0x000000ff00000000ULL) | \
25 (((x) >> 8) & 0x00000000ff000000ULL) | \
26 (((x) >> 24) & 0x0000000000ff0000ULL) | \
27 (((x) >> 40) & 0x000000000000ff00ULL) | \
28 (((x) >> 56) & 0x00000000000000ffULL)))
29
30/* The byte swapping macros have the form: */
31/* EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
32/* le (little-endian), NN is 16 or 32 (number of bits) and a, */
33/* if present, indicates that the endian side is a pointer to an */
34/* array of uint8_t bytes instead of an integer of the specified length. */
35/* h refers to the host's ordering method. */
36
37/* So, to convert a 32-bit integer stored in a buffer in little-endian */
38/* format into a uint32_t usable on this machine, you could use: */
39/* uint32_t value = le32atoh(&buf[3]); */
40/* To put that value back into the buffer, you could use: */
41/* htole32a(&buf[3], value); */
42
43/* Define aliases for the standard byte swapping macros */
44/* Arguments to these macros must be properly aligned on natural word */
45/* boundaries in order to work properly on all architectures */
46#ifndef htobe16
47# ifdef __HAVE_NTOHL
48# define htobe16(x) htons(x)
49# else
50# ifdef WORDS_BIGENDIAN
51# define htobe16(x) (x)
52# else
53# define htobe16(x) swap16(x)
54# endif
55# endif
56#endif
57#ifndef htobe32
58# ifdef __HAVE_NTOHL
59# define htobe32(x) htonl(x)
60# else
61# ifdef WORDS_BIGENDIAN
62# define htobe32(x) (x)
63# else
64# define htobe32(x) swap32(x)
65# endif
66# endif
67#endif
68#ifndef be16toh
69# define be16toh(x) htobe16(x)
70#endif
71#ifndef be32toh
72# define be32toh(x) htobe32(x)
73#endif
74
75#define HTOBE16(x) (x) = htobe16(x)
76#define HTOBE32(x) (x) = htobe32(x)
77#define BE32TOH(x) (x) = be32toh(x)
78#define BE16TOH(x) (x) = be16toh(x)
79
80/* On little endian machines, these macros are null */
81#ifndef htole16
82# define htole16(x) (x)
83#endif
84#ifndef htole32
85# define htole32(x) (x)
86#endif
87#ifndef htole64
88# define htole64(x) (x)
89#endif
90#ifndef le16toh
91# define le16toh(x) (x)
92#endif
93#ifndef le32toh
94# define le32toh(x) (x)
95#endif
96#ifndef le64toh
97# define le64toh(x) (x)
98#endif
99
100#define HTOLE16(x) (void) (x)
101#define HTOLE32(x) (void) (x)
102#define HTOLE64(x) (void) (x)
103#define LE16TOH(x) (void) (x)
104#define LE32TOH(x) (void) (x)
105#define LE64TOH(x) (void) (x)
106
107/* These don't have standard aliases */
108#ifndef htobe64
109# define htobe64(x) swap64(x)
110#endif
111#ifndef be64toh
112# define be64toh(x) swap64(x)
113#endif
114
115#define HTOBE64(x) (x) = htobe64(x)
116#define BE64TOH(x) (x) = be64toh(x)
117
118/* Define the C99 standard length-specific integer types */
119#include <stdint.h>
120
121/* Here are some macros to create integers from a byte array */
122/* These are used to get and put integers from/into a uint8_t array */
123/* with a specific endianness. This is the most portable way to generate */
124/* and read messages to a network or serial device. Each member of a */
125/* packet structure must be handled separately. */
126
127/* The i386 and compatibles can handle unaligned memory access, */
128/* so use the optimized macros above to do this job */
129#ifndef be16atoh
130# define be16atoh(x) be16toh(*(uint16_t*)(x))
131#endif
132#ifndef be32atoh
133# define be32atoh(x) be32toh(*(uint32_t*)(x))
134#endif
135#ifndef be64atoh
136# define be64atoh(x) be64toh(*(uint64_t*)(x))
137#endif
138#ifndef le16atoh
139# define le16atoh(x) le16toh(*(uint16_t*)(x))
140#endif
141#ifndef le32atoh
142# define le32atoh(x) le32toh(*(uint32_t*)(x))
143#endif
144#ifndef le64atoh
145# define le64atoh(x) le64toh(*(uint64_t*)(x))
146#endif
147
148#ifndef htob16a
149# define htobe16a(a,x) *(uint16_t*)(a) = htobe16(x)
150#endif
151#ifndef htobe32a
152# define htobe32a(a,x) *(uint32_t*)(a) = htobe32(x)
153#endif
154#ifndef htobe64a
155# define htobe64a(a,x) *(uint64_t*)(a) = htobe64(x)
156#endif
157#ifndef htole16a
158# define htole16a(a,x) *(uint16_t*)(a) = htole16(x)
159#endif
160#ifndef htole32a
161# define htole32a(a,x) *(uint32_t*)(a) = htole32(x)
162#endif
163#ifndef htole64a
164# define htole64a(a,x) *(uint64_t*)(a) = htole64(x)
165#endif
166
167#endif /* GP_BYTEORDER_H */