~ubuntu-branches/ubuntu/utopic/mtbl/utopic-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef MY_BYTEORDER_H
#define MY_BYTEORDER_H

#include "config.h"

#ifdef HAVE_ENDIAN_H
# include <endian.h>
#else
# ifdef HAVE_SYS_ENDIAN_H
#  include <sys/endian.h>
# endif
#endif

#if HAVE_DECL_HTOLE32
# define my_htole32 htole32
#else
# if defined(WORDS_BIGENDIAN)
#  define my_htole32 my_bswap32
# else
#  define my_htole32(x) (x)
# endif
#endif

#if HAVE_DECL_LE32TOH
# define my_le32toh le32toh
#else
# if defined(WORDS_BIGENDIAN)
#  define my_le32toh my_bswap32
# else
#  define my_le32toh(x) (x)
# endif
#endif

static inline uint32_t
my_bswap32(uint32_t x)
{
	return  ((x << 24) & 0xff000000 ) |
		((x <<  8) & 0x00ff0000 ) |
		((x >>  8) & 0x0000ff00 ) |
		((x >> 24) & 0x000000ff );
}

#endif /* MY_BYTEORDER_H */