1
2
3
4
5
6
7
8
9
10#ifndef XZ_CONFIG_H
11#define XZ_CONFIG_H
12
13
14
15
16
17
18
19
20
21#include <stdbool.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "xz.h"
26
27#define kmalloc(size, flags) malloc(size)
28#define kfree(ptr) free(ptr)
29#define vmalloc(size) malloc(size)
30#define vfree(ptr) free(ptr)
31
32#define memeq(a, b, size) (memcmp(a, b, size) == 0)
33#define memzero(buf, size) memset(buf, 0, size)
34
35#undef min
36#undef min_t
37#define min(x, y) ((x) < (y) ? (x) : (y))
38#define min_t(type, x, y) min(x, y)
39
40
41
42
43
44
45
46
47
48
49
50#ifndef __always_inline
51# ifdef __GNUC__
52# define __always_inline \
53 inline __attribute__((__always_inline__))
54# else
55# define __always_inline inline
56# endif
57#endif
58
59
60
61
62
63
64
65#ifndef noinline_for_stack
66# ifdef __GNUC__
67# define noinline_for_stack __attribute__((__noinline__))
68# else
69# define noinline_for_stack
70# endif
71#endif
72
73
74#ifndef get_unaligned_le32
75static inline uint32_t XZ_FUNC get_unaligned_le32(const uint8_t *buf)
76{
77 return (uint32_t)buf[0]
78 | ((uint32_t)buf[1] << 8)
79 | ((uint32_t)buf[2] << 16)
80 | ((uint32_t)buf[3] << 24);
81}
82#endif
83
84#ifndef get_unaligned_be32
85static inline uint32_t XZ_FUNC get_unaligned_be32(const uint8_t *buf)
86{
87 return (uint32_t)(buf[0] << 24)
88 | ((uint32_t)buf[1] << 16)
89 | ((uint32_t)buf[2] << 8)
90 | (uint32_t)buf[3];
91}
92#endif
93
94#ifndef put_unaligned_le32
95static inline void XZ_FUNC put_unaligned_le32(uint32_t val, uint8_t *buf)
96{
97 buf[0] = (uint8_t)val;
98 buf[1] = (uint8_t)(val >> 8);
99 buf[2] = (uint8_t)(val >> 16);
100 buf[3] = (uint8_t)(val >> 24);
101}
102#endif
103
104#ifndef put_unaligned_be32
105static inline void XZ_FUNC put_unaligned_be32(uint32_t val, uint8_t *buf)
106{
107 buf[0] = (uint8_t)(val >> 24);
108 buf[1] = (uint8_t)(val >> 16);
109 buf[2] = (uint8_t)(val >> 8);
110 buf[3] = (uint8_t)val;
111}
112#endif
113
114
115
116
117
118
119#ifndef get_le32
120# define get_le32 get_unaligned_le32
121#endif
122
123#endif
124