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 #ifndef UCX_UTILS_H
41 #define UCX_UTILS_H
42
43 #include "common.h"
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49
50
51
52 #define cx_for_n(varname, n)
for (
size_t varname =
0 ; (varname) < (n) ; (varname)++)
53
54
55
56
57 #ifdef __cplusplus
58 #define cx_swap_ptr(left, right)
do {
auto cx_tmp_swap_var = left; left = right; right = cx_tmp_swap_var;}
while(
0)
59 #else
60 #define cx_swap_ptr(left, right)
do {
void *cx_tmp_swap_var = left; left = right; right = cx_tmp_swap_var;}
while(
0)
61 #endif
62
63
64
65 #if (
__GNUC__ >=
5 || defined(__clang__)) && !defined(
CX_NO_SZMUL_BUILTIN)
66 #define CX_SZMUL_BUILTIN
67
68
69
70
71
72
73
74
75
76
77
78
79
80 #define cx_szmul(a, b, result) __builtin_mul_overflow(a, b, result)
81
82 #else
83
84
85
86
87
88
89
90
91
92
93
94 #define cx_szmul(a, b, result) cx_szmul_impl(a, b, result)
95
96
97
98
99
100
101
102
103
104
105
106
107
108 int cx_szmul_impl(
size_t a,
size_t b,
size_t *result);
109
110 #endif
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 __attribute__((__nonnull__(
1,
2,
3,
4)))
130 size_t cx_stream_bncopy(
131 void *src,
132 void *dest,
133 cx_read_func rfnc,
134 cx_write_func wfnc,
135 char *buf,
136 size_t bufsize,
137 size_t n
138 );
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 #define cx_stream_bcopy(src, dest, rfnc, wfnc, buf, bufsize) \
154 cx_stream_bncopy(src, dest, rfnc, wfnc, buf, bufsize,
SIZE_MAX)
155
156
157
158
159
160
161
162
163
164
165
166
167
168 __attribute__((__nonnull__))
169 size_t cx_stream_ncopy(
170 void *src,
171 void *dest,
172 cx_read_func rfnc,
173 cx_write_func wfnc,
174 size_t n
175 );
176
177
178
179
180
181
182
183
184
185
186
187
188 #define cx_stream_copy(src, dest, rfnc, wfnc) \
189 cx_stream_ncopy(src, dest, rfnc, wfnc,
SIZE_MAX)
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif
196