# gphoto2-endian.h

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