<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libmtp: /home/mandrake/rpm/BUILD/libmtp-1.0.2/src/gphoto2-endian.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_afadb87d2fbfeb62b40078349a549d44.html">src</a> </div> </div> <div class="contents"> <h1>gphoto2-endian.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* This file is generated automatically by configure */</span> <a name="l00002"></a>00002 <span class="comment">/* It is valid only for the system type x86_64-mandriva-linux-gnu */</span> <a name="l00003"></a>00003 <a name="l00004"></a>00004 <span class="preprocessor">#ifndef __BYTEORDER_H</span> <a name="l00005"></a>00005 <span class="preprocessor"></span><span class="preprocessor">#define __BYTEORDER_H</span> <a name="l00006"></a>00006 <span class="preprocessor"></span> <a name="l00007"></a>00007 <span class="comment">/* ntohl and relatives live here */</span> <a name="l00008"></a>00008 <span class="preprocessor">#include <arpa/inet.h></span> <a name="l00009"></a>00009 <a name="l00010"></a>00010 <span class="comment">/* Define generic byte swapping functions */</span> <a name="l00011"></a>00011 <span class="preprocessor">#include <byteswap.h></span> <a name="l00012"></a>00012 <span class="preprocessor">#define swap16(x) bswap_16(x)</span> <a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define swap32(x) bswap_32(x)</span> <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define swap64(x) bswap_64(x)</span> <a name="l00015"></a>00015 <span class="preprocessor"></span> <a name="l00016"></a>00016 <span class="comment">/* The byte swapping macros have the form: */</span> <a name="l00017"></a>00017 <span class="comment">/* EENN[a]toh or htoEENN[a] where EE is be (big endian) or */</span> <a name="l00018"></a>00018 <span class="comment">/* le (little-endian), NN is 16 or 32 (number of bits) and a, */</span> <a name="l00019"></a>00019 <span class="comment">/* if present, indicates that the endian side is a pointer to an */</span> <a name="l00020"></a>00020 <span class="comment">/* array of uint8_t bytes instead of an integer of the specified length. */</span> <a name="l00021"></a>00021 <span class="comment">/* h refers to the host's ordering method. */</span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="comment">/* So, to convert a 32-bit integer stored in a buffer in little-endian */</span> <a name="l00024"></a>00024 <span class="comment">/* format into a uint32_t usable on this machine, you could use: */</span> <a name="l00025"></a>00025 <span class="comment">/* uint32_t value = le32atoh(&buf[3]); */</span> <a name="l00026"></a>00026 <span class="comment">/* To put that value back into the buffer, you could use: */</span> <a name="l00027"></a>00027 <span class="comment">/* htole32a(&buf[3], value); */</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="comment">/* Define aliases for the standard byte swapping macros */</span> <a name="l00030"></a>00030 <span class="comment">/* Arguments to these macros must be properly aligned on natural word */</span> <a name="l00031"></a>00031 <span class="comment">/* boundaries in order to work properly on all architectures */</span> <a name="l00032"></a>00032 <span class="preprocessor">#ifndef htobe16</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor"># define htobe16(x) htons(x)</span> <a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#ifndef htobe32</span> <a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor"># define htobe32(x) htonl(x)</span> <a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#ifndef be16toh</span> <a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor"># define be16toh(x) ntohs(x)</span> <a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#ifndef be32toh</span> <a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor"># define be32toh(x) ntohl(x)</span> <a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00044"></a>00044 <span class="preprocessor"></span> <a name="l00045"></a>00045 <span class="preprocessor">#define HTOBE16(x) (x) = htobe16(x)</span> <a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define HTOBE32(x) (x) = htobe32(x)</span> <a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define BE32TOH(x) (x) = be32toh(x)</span> <a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define BE16TOH(x) (x) = be16toh(x)</span> <a name="l00049"></a>00049 <span class="preprocessor"></span> <a name="l00050"></a>00050 <span class="comment">/* On little endian machines, these macros are null */</span> <a name="l00051"></a>00051 <span class="preprocessor">#ifndef htole16</span> <a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor"># define htole16(x) (x)</span> <a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#ifndef htole32</span> <a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor"># define htole32(x) (x)</span> <a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#ifndef htole64</span> <a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor"># define htole64(x) (x)</span> <a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#ifndef le16toh</span> <a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor"># define le16toh(x) (x)</span> <a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#ifndef le32toh</span> <a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor"># define le32toh(x) (x)</span> <a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#ifndef le64toh</span> <a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor"># define le64toh(x) (x)</span> <a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00069"></a>00069 <span class="preprocessor"></span> <a name="l00070"></a>00070 <span class="preprocessor">#define HTOLE16(x) (void) (x)</span> <a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define HTOLE32(x) (void) (x)</span> <a name="l00072"></a>00072 <span class="preprocessor"></span><span class="preprocessor">#define HTOLE64(x) (void) (x)</span> <a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define LE16TOH(x) (void) (x)</span> <a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define LE32TOH(x) (void) (x)</span> <a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define LE64TOH(x) (void) (x)</span> <a name="l00076"></a>00076 <span class="preprocessor"></span> <a name="l00077"></a>00077 <span class="comment">/* These don't have standard aliases */</span> <a name="l00078"></a>00078 <span class="preprocessor">#ifndef htobe64</span> <a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor"># define htobe64(x) swap64(x)</span> <a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#ifndef be64toh</span> <a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor"># define be64toh(x) swap64(x)</span> <a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00084"></a>00084 <span class="preprocessor"></span> <a name="l00085"></a>00085 <span class="preprocessor">#define HTOBE64(x) (x) = htobe64(x)</span> <a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#define BE64TOH(x) (x) = be64toh(x)</span> <a name="l00087"></a>00087 <span class="preprocessor"></span> <a name="l00088"></a>00088 <span class="comment">/* Define the C99 standard length-specific integer types */</span> <a name="l00089"></a>00089 <span class="preprocessor">#include <_stdint.h></span> <a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="comment">/* Here are some macros to create integers from a byte array */</span> <a name="l00092"></a>00092 <span class="comment">/* These are used to get and put integers from/into a uint8_t array */</span> <a name="l00093"></a>00093 <span class="comment">/* with a specific endianness. This is the most portable way to generate */</span> <a name="l00094"></a>00094 <span class="comment">/* and read messages to a network or serial device. Each member of a */</span> <a name="l00095"></a>00095 <span class="comment">/* packet structure must be handled separately. */</span> <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="comment">/* Non-optimized but portable macros */</span> <a name="l00098"></a>00098 <span class="preprocessor">#define be16atoh(x) ((uint16_t)(((x)[0]<<8)|(x)[1]))</span> <a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#define be32atoh(x) ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))</span> <a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor">#define be64atoh_x(x,off,shift) (((uint64_t)((x)[off]))<<shift)</span> <a name="l00101"></a>00101 <span class="preprocessor"></span><span class="preprocessor">#define be64atoh(x) ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \</span> <a name="l00102"></a>00102 <span class="preprocessor"> be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))</span> <a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define le16atoh(x) ((uint16_t)(((x)[1]<<8)|(x)[0]))</span> <a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define le32atoh(x) ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))</span> <a name="l00105"></a>00105 <span class="preprocessor"></span><span class="preprocessor">#define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)</span> <a name="l00106"></a>00106 <span class="preprocessor"></span><span class="preprocessor">#define le64atoh(x) ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \</span> <a name="l00107"></a>00107 <span class="preprocessor"> le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))</span> <a name="l00108"></a>00108 <span class="preprocessor"></span> <a name="l00109"></a>00109 <span class="preprocessor">#define htobe16a(a,x) (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)</span> <a name="l00110"></a>00110 <span class="preprocessor"></span><span class="preprocessor">#define htobe32a(a,x) (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \</span> <a name="l00111"></a>00111 <span class="preprocessor"> (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)</span> <a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#define htobe64a(a,x) (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \</span> <a name="l00113"></a>00113 <span class="preprocessor"> (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \</span> <a name="l00114"></a>00114 <span class="preprocessor"> (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \</span> <a name="l00115"></a>00115 <span class="preprocessor"> (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)</span> <a name="l00116"></a>00116 <span class="preprocessor"></span><span class="preprocessor">#define htole16a(a,x) (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)</span> <a name="l00117"></a>00117 <span class="preprocessor"></span><span class="preprocessor">#define htole32a(a,x) (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \</span> <a name="l00118"></a>00118 <span class="preprocessor"> (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)</span> <a name="l00119"></a>00119 <span class="preprocessor"></span><span class="preprocessor">#define htole64a(a,x) (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \</span> <a name="l00120"></a>00120 <span class="preprocessor"> (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \</span> <a name="l00121"></a>00121 <span class="preprocessor"> (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \</span> <a name="l00122"></a>00122 <span class="preprocessor"> (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)</span> <a name="l00123"></a>00123 <span class="preprocessor"></span> <a name="l00124"></a>00124 <span class="preprocessor">#endif </span><span class="comment">/*__BYTEORDER_H*/</span> </pre></div></div> <hr size="1"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> </body> </html>