gphoto2-endian.h

00001 /* This file is generated automatically by configure */
00002 /* It is valid only for the system type powerpc-mandriva-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 #define htobe16(x) htons(x)
00033 #define htobe32(x) htonl(x)
00034 #define be16toh(x) ntohs(x)
00035 #define be32toh(x) ntohl(x)
00036 
00037 #define HTOBE16(x) (x) = htobe16(x)
00038 #define HTOBE32(x) (x) = htobe32(x)
00039 #define BE32TOH(x) (x) = be32toh(x)
00040 #define BE16TOH(x) (x) = be16toh(x)
00041 
00042 /* Define our own extended byte swapping macros for big-endian machines */
00043 #define htole16(x)      swap16(x)
00044 #define htole32(x)      swap32(x)
00045 #define le16toh(x)      swap16(x)
00046 #define le32toh(x)      swap32(x)
00047 #define le64toh(x)      swap64(x)
00048 
00049 #define htobe64(x)      (x)
00050 #define be64toh(x)      (x)
00051 
00052 #define HTOLE16(x)      (x) = htole16(x)
00053 #define HTOLE32(x)      (x) = htole32(x)
00054 #define LE16TOH(x)      (x) = le16toh(x)
00055 #define LE32TOH(x)      (x) = le32toh(x)
00056 #define LE64TOH(x)      (x) = le64toh(x)
00057 
00058 #define HTOBE64(x)      (void) (x)
00059 #define BE64TOH(x)      (void) (x)
00060 
00061 /* Define the C99 standard length-specific integer types */
00062 #include "libptp-stdint.h"
00063 
00064 /* Here are some macros to create integers from a byte array */
00065 /* These are used to get and put integers from/into a uint8_t array */
00066 /* with a specific endianness.  This is the most portable way to generate */
00067 /* and read messages to a network or serial device.  Each member of a */
00068 /* packet structure must be handled separately. */
00069 
00070 /* Non-optimized but portable macros */
00071 #define be16atoh(x)     ((uint16_t)(((x)[0]<<8)|(x)[1]))
00072 #define be32atoh(x)     ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
00073 #define be64atoh_x(x,off,shift)         (((uint64_t)((x)[off]))<<shift)
00074 #define be64atoh(x)     ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \
00075         be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
00076 #define le16atoh(x)     ((uint16_t)(((x)[1]<<8)|(x)[0]))
00077 #define le32atoh(x)     ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
00078 #define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
00079 #define le64atoh(x)     ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \
00080         le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
00081 
00082 #define htobe16a(a,x)   (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
00083 #define htobe32a(a,x)   (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \
00084         (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
00085 #define htobe64a(a,x)   (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \
00086         (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \
00087         (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \
00088         (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
00089 #define htole16a(a,x)   (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00090 #define htole32a(a,x)   (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
00091         (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00092 #define htole64a(a,x)   (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \
00093         (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \
00094         (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
00095         (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00096 
00097 #endif /*__BYTEORDER_H*/

Generated on Mon Aug 6 22:49:52 2007 for libmtp by  doxygen 1.5.3