General purpose utility functions.
More...
Go to the source code of this file.
|
#define | cx_for_n(varname, n) for (size_t varname = 0 ; (varname) < (n) ; (varname)++) |
| Convenience macro for a for loop that counts from zero to n-1.
|
|
#define | cx_swap_ptr(left, right) do {void *cx_tmp_swap_var = left; left = right; right = cx_tmp_swap_var;} while(0) |
| Convenience macro for swapping two pointers.
|
|
#define | cx_szmul(a, b, result) cx_szmul_impl(a, b, result) |
| Performs a multiplication of size_t values and checks for overflow.
|
|
#define | cx_stream_bcopy(src, dest, rfnc, wfnc, buf, bufsize) cx_stream_bncopy(src, dest, rfnc, wfnc, buf, bufsize, SIZE_MAX) |
| Reads data from a stream and writes it to another stream.
|
|
#define | cx_stream_copy(src, dest, rfnc, wfnc) cx_stream_ncopy(src, dest, rfnc, wfnc, SIZE_MAX) |
| Reads data from a stream and writes it to another stream.
|
|
|
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_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.
|
|
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.
|
|
General purpose utility functions.
- Author
- Mike Becker
-
Olaf Wintermann
- Version
- 3.0
- Copyright
- 2-Clause BSD License
◆ cx_stream_bcopy
#define cx_stream_bcopy |
( |
|
src, |
|
|
|
dest, |
|
|
|
rfnc, |
|
|
|
wfnc, |
|
|
|
buf, |
|
|
|
bufsize |
|
) |
| cx_stream_bncopy(src, dest, rfnc, wfnc, buf, bufsize, SIZE_MAX) |
Reads data from a stream and writes it to another stream.
- Parameters
-
src | the source stream |
dest | the destination stream |
rfnc | the read function |
wfnc | the write function |
buf | a pointer to the copy buffer or NULL if a buffer shall be implicitly created on the heap |
bufsize | the size of the copy buffer - if buf is NULL you can set this to zero to let the implementation decide |
- Returns
- total number of bytes copied
◆ cx_stream_copy
#define cx_stream_copy |
( |
|
src, |
|
|
|
dest, |
|
|
|
rfnc, |
|
|
|
wfnc |
|
) |
| cx_stream_ncopy(src, dest, rfnc, wfnc, SIZE_MAX) |
Reads data from a stream and writes it to another stream.
The data is temporarily stored in a stack allocated buffer.
- Parameters
-
src | the source stream |
dest | the destination stream |
rfnc | the read function |
wfnc | the write function |
- Returns
- total number of bytes copied
◆ cx_szmul
Performs a multiplication of size_t values and checks for overflow.
- Parameters
-
a | first operand |
b | second operand |
result | a pointer to a size_t, where the result should be stored |
- Returns
- zero, if no overflow occurred and the result is correct, non-zero otherwise
◆ cx_stream_bncopy()
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.
- Parameters
-
src | the source stream |
dest | the destination stream |
rfnc | the read function |
wfnc | the write function |
buf | a pointer to the copy buffer or NULL if a buffer shall be implicitly created on the heap |
bufsize | the size of the copy buffer - if buf is NULL you can set this to zero to let the implementation decide |
n | the maximum number of bytes that shall be copied. If this is larger than bufsize , the content is copied over multiple iterations. |
- Returns
- the total number of bytes copied
◆ cx_stream_ncopy()
Reads data from a stream and writes it to another stream.
The data is temporarily stored in a stack allocated buffer.
- Parameters
-
src | the source stream |
dest | the destination stream |
rfnc | the read function |
wfnc | the write function |
n | the maximum number of bytes that shall be copied. |
- Returns
- total number of bytes copied
◆ cx_szmul_impl()
int cx_szmul_impl |
( |
size_t |
a, |
|
|
size_t |
b, |
|
|
size_t * |
result |
|
) |
| |
Performs a multiplication of size_t values and checks for overflow.
This is a custom implementation in case there is no compiler builtin available.
- Parameters
-
a | first operand |
b | second operand |
result | a pointer to a size_t where the result should be stored |
- Returns
- zero, if no overflow occurred and the result is correct, non-zero otherwise