portability.h revision 2aa494dcfe701e080e62f3d2a36af84b2ee16837
1// Humor glibc to get dprintf, then #define it to something more portable.
2#define _GNU_SOURCE
3#include <stdio.h>
4#define fdprintf(...) dprintf(__VA_ARGS__)
5
6
7#ifndef __APPLE__
8#include <byteswap.h>
9#include <endian.h>
10
11#if __BYTE_ORDER == __BIG_ENDIAN
12#define IS_BIG_ENDIAN 1
13#else
14#define IS_BIG_ENDIAN 0
15#endif
16
17#else
18
19#ifdef __BIG_ENDIAN__
20#define IS_BIG_ENDIAN 1
21#else
22#define IS_BIG_ENDIAN 0
23#endif
24
25#endif
26
27#if IS_BIG_ENDIAN
28#define IS_LITTLE_ENDIAN 0
29#define SWAP_BE16(x) (x)
30#define SWAP_BE32(x) (x)
31#define SWAP_BE64(x) (x)
32#define SWAP_LE16(x) bswap_16(x)
33#define SWAP_LE32(x) bswap_32(x)
34#define SWAP_LE64(x) bswap_64(x)
35#else
36#define IS_LITTLE_ENDIAN 1
37#define SWAP_BE16(x) bswap_16(x)
38#define SWAP_BE32(x) bswap_32(x)
39#define SWAP_BE64(x) bswap_64(x)
40#define SWAP_LE16(x) (x)
41#define SWAP_LE32(x) (x)
42#define SWAP_LE64(x) (x)
43#endif
44
45// Some versions of gcc produce spurious "may be uninitialized" warnings in
46// cases where it provably can't happen.  Unfortunately, although this warning
47// is calculated and produced separately from the "is definitely used
48// uninitialized" warnings, there's no way to turn off the broken spurious "may
49// be" warnings without also turning off the non-broken "is" warnings.
50
51#if CFG_TOYBOX_DEBUG
52#define GCC_BUG =0
53#else
54#define GCC_BUG
55#endif
56