gphoto2-endian.h

00001 /* This file is generated automatically by configure */
00002 /* It is valid only for the system type i386-unknown-openbsd4.9 */
00003 
00004 #ifndef __BYTEORDER_H
00005 #define __BYTEORDER_H
00006 
00007 /* ntohl and relatives live here */
00008 #include <arpa/inet.h>
00009 
00010 /* swap32 and swap16 are defined in machine/endian.h */
00011 
00012 /* The byte swapping macros have the form: */
00013 /*   EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
00014 /* le (little-endian), NN is 16 or 32 (number of bits) and a, */
00015 /* if present, indicates that the endian side is a pointer to an */
00016 /* array of uint8_t bytes instead of an integer of the specified length. */
00017 /* h refers to the host's ordering method. */
00018 
00019 /* So, to convert a 32-bit integer stored in a buffer in little-endian */
00020 /* format into a uint32_t usable on this machine, you could use: */
00021 /*   uint32_t value = le32atoh(&buf[3]); */
00022 /* To put that value back into the buffer, you could use: */
00023 /*   htole32a(&buf[3], value); */
00024 
00025 /* Define aliases for the standard byte swapping macros */
00026 /* Arguments to these macros must be properly aligned on natural word */
00027 /* boundaries in order to work properly on all architectures */
00028 #ifndef htobe16
00029 # define htobe16(x) htons(x)
00030 #endif
00031 #ifndef htobe32
00032 # define htobe32(x) htonl(x)
00033 #endif
00034 #ifndef be16toh
00035 # define be16toh(x) ntohs(x)
00036 #endif
00037 #ifndef be32toh
00038 # define be32toh(x) ntohl(x)
00039 #endif
00040 
00041 #define HTOBE16(x) (x) = htobe16(x)
00042 #define HTOBE32(x) (x) = htobe32(x)
00043 #define BE32TOH(x) (x) = be32toh(x)
00044 #define BE16TOH(x) (x) = be16toh(x)
00045 
00046 /* On little endian machines, these macros are null */
00047 #ifndef htole16
00048 # define htole16(x)      (x)
00049 #endif
00050 #ifndef htole32
00051 # define htole32(x)      (x)
00052 #endif
00053 #ifndef htole64
00054 # define htole64(x)      (x)
00055 #endif
00056 #ifndef le16toh
00057 # define le16toh(x)      (x)
00058 #endif
00059 #ifndef le32toh
00060 # define le32toh(x)      (x)
00061 #endif
00062 #ifndef le64toh
00063 # define le64toh(x)      (x)
00064 #endif
00065 
00066 #define HTOLE16(x)      (void) (x)
00067 #define HTOLE32(x)      (void) (x)
00068 #define HTOLE64(x)      (void) (x)
00069 #define LE16TOH(x)      (void) (x)
00070 #define LE32TOH(x)      (void) (x)
00071 #define LE64TOH(x)      (void) (x)
00072 
00073 /* These don't have standard aliases */
00074 #ifndef htobe64
00075 # define htobe64(x)      swap64(x)
00076 #endif
00077 #ifndef be64toh
00078 # define be64toh(x)      swap64(x)
00079 #endif
00080 
00081 #define HTOBE64(x)      (x) = htobe64(x)
00082 #define BE64TOH(x)      (x) = be64toh(x)
00083 
00084 /* Define the C99 standard length-specific integer types */
00085 #include <_stdint.h>
00086 
00087 /* Here are some macros to create integers from a byte array */
00088 /* These are used to get and put integers from/into a uint8_t array */
00089 /* with a specific endianness.  This is the most portable way to generate */
00090 /* and read messages to a network or serial device.  Each member of a */
00091 /* packet structure must be handled separately. */
00092 
00093 /* The i386 and compatibles can handle unaligned memory access, */
00094 /* so use the optimized macros above to do this job */
00095 #ifndef be16atoh
00096 # define be16atoh(x)     be16toh(*(uint16_t*)(x))
00097 #endif
00098 #ifndef be32atoh
00099 # define be32atoh(x)     be32toh(*(uint32_t*)(x))
00100 #endif
00101 #ifndef be64atoh
00102 # define be64atoh(x)     be64toh(*(uint64_t*)(x))
00103 #endif
00104 #ifndef le16atoh
00105 # define le16atoh(x)     le16toh(*(uint16_t*)(x))
00106 #endif
00107 #ifndef le32atoh
00108 # define le32atoh(x)     le32toh(*(uint32_t*)(x))
00109 #endif
00110 #ifndef le64atoh
00111 # define le64atoh(x)     le64toh(*(uint64_t*)(x))
00112 #endif
00113 
00114 #ifndef htob16a
00115 # define htobe16a(a,x)   *(uint16_t*)(a) = htobe16(x)
00116 #endif
00117 #ifndef htobe32a
00118 # define htobe32a(a,x)   *(uint32_t*)(a) = htobe32(x)
00119 #endif
00120 #ifndef htobe64a
00121 # define htobe64a(a,x)   *(uint64_t*)(a) = htobe64(x)
00122 #endif
00123 #ifndef htole16a
00124 # define htole16a(a,x)   *(uint16_t*)(a) = htole16(x)
00125 #endif
00126 #ifndef htole32a
00127 # define htole32a(a,x)   *(uint32_t*)(a) = htole32(x)
00128 #endif
00129 #ifndef htole64a
00130 # define htole64a(a,x)   *(uint64_t*)(a) = htole64(x)
00131 #endif
00132 
00133 #endif /*__BYTEORDER_H*/