db_updater: Put parentheses back
[merlin.git] / compat.h
blobaaeb25d3cc4f3e9ae4389be3f4bc5f3b58f5e98e
1 #ifndef INCLUDE_compat_h__
2 #define INCLUDE_compat_h__
4 /*
5 * CHAR_BIT really should be 8 on all systems we care about
6 */
7 #ifndef CHAR_BIT
8 # define CHAR_BIT 8
9 #endif
11 #ifdef __WORDSIZE
12 # define COMPAT_WORDSIZE __WORDSIZE
13 #else
14 # define COMPAT_WORDSIZE (sizeof(void *) * CHAR_BIT)
15 #endif
17 /* runtime detection of endianness with GNU style macros */
18 #define COMPAT_LITTLE_ENDIAN 1234
19 #define COMPAT_BIG_ENDIAN 4321
21 static inline unsigned int endianness(void)
23 int i = 1;
25 #ifdef __BYTE_ORDER
26 if (__BYTE_ORDER == COMPAT_LITTLE_ENDIAN || __BYTE_ORDER == COMPAT_BIG_ENDIAN)
27 return __BYTE_ORDER;
28 #elif defined(_BYTE_ORDER)
29 if (_BYTE_ORDER == COMPAT_LITTLE_ENDIAN || _BYTE_ORDER == COMPAT_BIG_ENDIAN)
30 return _BYTE_ORDER;
31 #endif /* __BYTE_ORDER */
33 if (((char *)&i)[0] == 1)
34 return COMPAT_LITTLE_ENDIAN;
36 return COMPAT_BIG_ENDIAN;
39 #ifdef NEEDS_MEMRCHR
40 extern void *memrchr(const void *s, int c, size_t n);
41 #endif
43 #ifdef NEEDS_ASPRINTF
44 #include <stdarg.h>
45 extern int asprintf(char **strp, const char *fmt, ...);
46 extern int vasprintf(char **strp, const char *fmt, va_list ap);
47 #endif
49 #ifndef NEBATTR_CHECK_ALERT
50 # define NEBATTR_CHECK_ALERT 1
51 #endif
53 #endif /* INCLUDE_compat_h__ */