52#define cx_for_n(varname, n) for (size_t varname = 0 ; (varname) < (n) ; (varname)++)
58#define cx_swap_ptr(left, right) do {auto cx_tmp_swap_var = left; left = right; right = cx_tmp_swap_var;} while(0)
60#define cx_swap_ptr(left, right) do {void *cx_tmp_swap_var = left; left = right; right = cx_tmp_swap_var;} while(0)
65#if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN)
66#define CX_SZMUL_BUILTIN
80#define cx_szmul(a, b, result) __builtin_mul_overflow(a, b, result)
94#define cx_szmul(a, b, result) cx_szmul_impl(a, b, result)
153#define cx_stream_bcopy(src, dest, rfnc, wfnc, buf, bufsize) \
154 cx_stream_bncopy(src, dest, rfnc, wfnc, buf, bufsize, SIZE_MAX)
188#define cx_stream_copy(src, dest, rfnc, wfnc) \
189 cx_stream_ncopy(src, dest, rfnc, wfnc, SIZE_MAX)
Common definitions and feature checks.
size_t(* cx_read_func)(void *, size_t, size_t, void *)
Function pointer compatible with fread-like functions.
Definition: common.h:113
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition: common.h:127
size_t(* cx_write_func)(void const *, size_t, size_t, void *)
Function pointer compatible with fwrite-like functions.
Definition: common.h:103
int cx_szmul_impl(size_t a, size_t b, size_t *result)
Performs a multiplication of size_t values and checks for overflow.
size_t cx_stream_ncopy(void *src, void *dest, cx_read_func rfnc, cx_write_func wfnc, size_t n)
Reads data from a stream and writes it to another stream.
size_t cx_stream_bncopy(void *src, void *dest, cx_read_func rfnc, cx_write_func wfnc, char *buf, size_t bufsize, size_t n)
Reads data from a stream and writes it to another stream.