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