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