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

« back to all changes in this revision

Viewing changes to libmy/my_byteorder.h

  • Committer: Package Import Robot
  • Author(s): Robert S. Edmonds
  • Date: 2014-01-21 16:30:22 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140121163022-g1077ma2csn1gne8
Tags: 0.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef MY_BYTEORDER_H
 
2
#define MY_BYTEORDER_H
 
3
 
 
4
#include "config.h"
 
5
 
 
6
#ifdef HAVE_ENDIAN_H
 
7
# include <endian.h>
 
8
#else
 
9
# ifdef HAVE_SYS_ENDIAN_H
 
10
#  include <sys/endian.h>
 
11
# endif
 
12
#endif
 
13
 
 
14
#if HAVE_DECL_HTOLE32
 
15
# define my_htole32 htole32
 
16
#else
 
17
# if defined(WORDS_BIGENDIAN)
 
18
#  define my_htole32 my_bswap32
 
19
# else
 
20
#  define my_htole32(x) (x)
 
21
# endif
 
22
#endif
 
23
 
 
24
#if HAVE_DECL_LE32TOH
 
25
# define my_le32toh le32toh
 
26
#else
 
27
# if defined(WORDS_BIGENDIAN)
 
28
#  define my_le32toh my_bswap32
 
29
# else
 
30
#  define my_le32toh(x) (x)
 
31
# endif
 
32
#endif
 
33
 
 
34
static inline uint32_t
 
35
my_bswap32(uint32_t x)
 
36
{
 
37
        return  ((x << 24) & 0xff000000 ) |
 
38
                ((x <<  8) & 0x00ff0000 ) |
 
39
                ((x >>  8) & 0x0000ff00 ) |
 
40
                ((x >> 24) & 0x000000ff );
 
41
}
 
42
 
 
43
#endif /* MY_BYTEORDER_H */