Coverage Report

Created: 2026-07-16 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/zendian.h
Line
Count
Source
1
/* zendian.h -- define BYTE_ORDER for endian tests
2
 * For conditions of distribution and use, see copyright notice in zlib.h
3
 */
4
5
#ifndef ENDIAN_H_
6
#define ENDIAN_H_
7
8
/* First check whether the compiler knows the target __BYTE_ORDER__. */
9
#if defined(__BYTE_ORDER__)
10
#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
11
#    if !defined(LITTLE_ENDIAN)
12
#      define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
13
#    endif
14
#    if !defined(BYTE_ORDER)
15
#      define BYTE_ORDER LITTLE_ENDIAN
16
#    endif
17
#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
18
#    if !defined(BIG_ENDIAN)
19
#      define BIG_ENDIAN __ORDER_BIG_ENDIAN__
20
#    endif
21
#    if !defined(BYTE_ORDER)
22
#      define BYTE_ORDER BIG_ENDIAN
23
#    endif
24
#  endif
25
#elif defined(__MINGW32__)
26
#  include <sys/param.h>
27
#elif defined(_WIN32)
28
#  define LITTLE_ENDIAN 1234
29
#  define BIG_ENDIAN 4321
30
#  if defined(ARCH_X86) || defined(ARCH_IA64) || defined(ARCH_ARM)
31
#    define BYTE_ORDER LITTLE_ENDIAN
32
#  else
33
#    error Unknown endianness!
34
#  endif
35
#elif defined(__linux__)
36
#  include <endian.h>
37
#elif defined(__APPLE__)
38
#  include <machine/endian.h>
39
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
40
#  include <sys/endian.h>
41
#elif defined(__sun) || defined(sun)
42
#  include <sys/byteorder.h>
43
#  if !defined(LITTLE_ENDIAN)
44
#    define LITTLE_ENDIAN 4321
45
#   endif
46
#  if !defined(BIG_ENDIAN)
47
#    define BIG_ENDIAN 1234
48
#  endif
49
#  if !defined(BYTE_ORDER)
50
#    if defined(_BIG_ENDIAN)
51
#      define BYTE_ORDER BIG_ENDIAN
52
#    else
53
#      define BYTE_ORDER LITTLE_ENDIAN
54
#    endif
55
#  endif
56
#else
57
#  include <endian.h>
58
#endif
59
60
#if !defined(BYTE_ORDER) || (!defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN))
61
#  error "Unknown byte order"
62
#endif
63
64
#if !defined(LITTLE_ENDIAN)
65
#  if BIG_ENDIAN == 1234
66
#    define LITTLE_ENDIAN 4321
67
#  elif BIG_ENDIAN == 4321
68
#    define LITTLE_ENDIAN 1234
69
#  else
70
#    define LITTLE_ENDIAN -1
71
#  endif
72
#elif !defined(BIG_ENDIAN)
73
#  if LITTLE_ENDIAN == 1234
74
#    define BIG_ENDIAN 4321
75
#  elif LITTLE_ENDIAN == 4321
76
#    define BIG_ENDIAN 1234
77
#  else
78
#    define BIG_ENDIAN -1
79
#  endif
80
#endif
81
82
#if BYTE_ORDER == LITTLE_ENDIAN
83
7.74k
#  define Z_U16_TO_LE(x)    (x)
84
1.68M
#  define Z_U32_TO_LE(x)    (x)
85
56.6k
#  define Z_U64_TO_LE(x)    (x)
86
#  define Z_U16_FROM_LE(x)  (x)
87
1.68M
#  define Z_U32_FROM_LE(x)  (x)
88
1.68M
#  define Z_U64_FROM_LE(x)  (x)
89
1.52k
#  define Z_U16_TO_BE(x)    ZSWAP16(x)
90
1.52k
#  define Z_U32_TO_BE(x)    ZSWAP32(x)
91
#  define Z_U64_TO_BE(x)    ZSWAP64(x)
92
#  define Z_U16_FROM_BE(x)  ZSWAP16(x)
93
#  define Z_U32_FROM_BE(x)  ZSWAP32(x)
94
#  define Z_U64_FROM_BE(x)  ZSWAP64(x)
95
#elif BYTE_ORDER == BIG_ENDIAN
96
#  define Z_U16_TO_LE(x)    ZSWAP16(x)
97
#  define Z_U32_TO_LE(x)    ZSWAP32(x)
98
#  define Z_U64_TO_LE(x)    ZSWAP64(x)
99
#  define Z_U16_FROM_LE(x)  ZSWAP16(x)
100
#  define Z_U32_FROM_LE(x)  ZSWAP32(x)
101
#  define Z_U64_FROM_LE(x)  ZSWAP64(x)
102
#  define Z_U16_TO_BE(x)    (x)
103
#  define Z_U32_TO_BE(x)    (x)
104
#  define Z_U64_TO_BE(x)    (x)
105
#  define Z_U16_FROM_BE(x)  (x)
106
#  define Z_U32_FROM_BE(x)  (x)
107
#  define Z_U64_FROM_BE(x)  (x)
108
#endif
109
110
#endif