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