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