File: byteorder.h

package info (click to toggle)
multipath-tools 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,992 kB
  • sloc: ansic: 63,788; perl: 1,622; makefile: 729; sh: 647; pascal: 150
file content (44 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (4)
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
44
#ifndef BYTEORDER_H_INCLUDED
#define BYTEORDER_H_INCLUDED

#ifdef __linux__
#  include <endian.h>
#  include <byteswap.h>
#else
#  error unsupported
#endif

#if BYTE_ORDER == LITTLE_ENDIAN
#  define le16_to_cpu(x) (uint16_t)(x)
#  define be16_to_cpu(x) bswap_16(x)
#  define le32_to_cpu(x) (uint32_t)(x)
#  define le64_to_cpu(x) (uint64_t)(x)
#  define be32_to_cpu(x) bswap_32(x)
#  define be64_to_cpu(x) bswap_64(x)
#elif BYTE_ORDER == BIG_ENDIAN
#  define le16_to_cpu(x) bswap_16(x)
#  define be16_to_cpu(x) (uint16_t)(x)
#  define le32_to_cpu(x) bswap_32(x)
#  define le64_to_cpu(x) bswap_64(x)
#  define be32_to_cpu(x) (uint32_t)(x)
#  define be64_to_cpu(x) (uint64_t)(x)
#else
#  error unsupported
#endif

#define cpu_to_le16(x) le16_to_cpu(x)
#define cpu_to_be16(x) be16_to_cpu(x)
#define cpu_to_le32(x) le32_to_cpu(x)
#define cpu_to_be32(x) be32_to_cpu(x)
#define cpu_to_le64(x) le64_to_cpu(x)
#define cpu_to_be64(x) be64_to_cpu(x)

struct be64 {
	uint64_t _v;
};

#define get_be64(x) be64_to_cpu((x)._v)
#define put_be64(x, y) do { (x)._v = cpu_to_be64(y); } while (0)


#endif				/* BYTEORDER_H_INCLUDED */