MythTV  master
bswap.h
Go to the documentation of this file.
1 #ifndef MYTHTV_BSWAP_H
2 #define MYTHTV_BSWAP_H
3 
4 #include <cstdint> /* uint32_t */
5 
6 #if HAVE_BYTESWAP_H
7 # include <byteswap.h> /* bswap_16|32|64 */
8 #elif HAVE_SYS_ENDIAN_H
9 # include <sys/endian.h>
10 # if !defined(bswap_16) && defined(bswap16)
11 # define bswap_16(x) bswap16(x)
12 # endif
13 # if !defined(bswap_32) && defined(bswap32)
14 # define bswap_32(x) bswap32(x)
15 # endif
16 # if !defined(bswap_64) && defined(bswap64)
17 # define bswap_64(x) bswap64(x)
18 # endif
19 #elif CONFIG_DARWIN
20 # include <libkern/OSByteOrder.h>
21 # define bswap_16(x) OSSwapInt16(x)
22 # define bswap_32(x) OSSwapInt32(x)
23 # define bswap_64(x) OSSwapInt64(x)
24 #elif HAVE_BIGENDIAN
25 # error Byte swapping functions not defined for this platform
26 #endif
27 
28 #ifdef bswap_32
29 // TODO: Any reason we choose not to use bswap_64 for this?
30 static __inline__ double bswap_dbl(double x)
31 {
32  union {
33  uint32_t l[2];
34  double d;
35  } w, r;
36  w.d = x;
37  r.l[0] = bswap_32(w.l[1]);
38  r.l[1] = bswap_32(w.l[0]);
39  return r.d;
40 }
41 #endif
42 
43 #endif /* ndef MYTHTV_BSWAP_H */
static const uint16_t * d