blob: d5c2fdb79527350896c0400a09d1b97064f8d484 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#ifndef BASE64_ENV_H
#define BASE64_ENV_H
// This header file contains macro definitions that describe certain aspects of
// the compile-time environment. Compatibility and portability macros go here.
// Define machine endianness. This is for GCC:
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
# define BASE64_LITTLE_ENDIAN 1
#else
# define BASE64_LITTLE_ENDIAN 0
#endif
// This is for Clang:
#ifdef __LITTLE_ENDIAN__
# define BASE64_LITTLE_ENDIAN 1
#endif
#ifdef __BIG_ENDIAN__
# define BASE64_LITTLE_ENDIAN 0
#endif
// MSVC++ needs intrin.h for _byteswap_uint64 (issue #68):
#if BASE64_LITTLE_ENDIAN && defined(_MSC_VER)
# include <intrin.h>
#endif
// Endian conversion functions:
#if BASE64_LITTLE_ENDIAN
# ifdef _MSC_VER
// Microsoft Visual C++:
# define BASE64_HTOBE32(x) _byteswap_ulong(x)
# define BASE64_HTOBE64(x) _byteswap_uint64(x)
# else
// GCC and Clang:
# define BASE64_HTOBE32(x) __builtin_bswap32(x)
# define BASE64_HTOBE64(x) __builtin_bswap64(x)
# endif
#else
// No conversion needed:
# define BASE64_HTOBE32(x) (x)
# define BASE64_HTOBE64(x) (x)
#endif
// Detect word size:
#if defined (__x86_64__)
// This also works for the x32 ABI, which has a 64-bit word size.
# define BASE64_WORDSIZE 64
#elif defined (_INTEGRAL_MAX_BITS)
# define BASE64_WORDSIZE _INTEGRAL_MAX_BITS
#elif defined (__WORDSIZE)
# define BASE64_WORDSIZE __WORDSIZE
#elif defined (__SIZE_WIDTH__)
# define BASE64_WORDSIZE __SIZE_WIDTH__
#else
# error BASE64_WORDSIZE_NOT_DEFINED
#endif
// End-of-file definitions.
// Almost end-of-file when waiting for the last '=' character:
#define BASE64_AEOF 1
// End-of-file when stream end has been reached or invalid input provided:
#define BASE64_EOF 2
// GCC 7 defaults to issuing a warning for fallthrough in switch statements,
// unless the fallthrough cases are marked with an attribute. As we use
// fallthrough deliberately, define an alias for the attribute:
#if __GNUC__ >= 7
# define BASE64_FALLTHROUGH __attribute__((fallthrough));
#else
# define BASE64_FALLTHROUGH
#endif
#endif // BASE64_ENV_H
|