#include <stddef.h>
#include <assert.h>
Go to the source code of this file.
Heap allocation | |
#define | VL_PRINTF(format,...) ((*vl_printf_func)((format), __VA_ARGS__)) |
Call user-customizable printf function. | |
#define | VL_PRINT(string) ((*vl_printf_func)(string)) |
Call user-customizable printf function (no varags). | |
void | vl_set_alloc_func (void *(*malloc_func)(vl_size), void *(*realloc_func)(void *, vl_size), void *(*calloc_func)(vl_size, vl_size), void(*free_func)(void *)) |
Set memory allocation functions. | |
VL_INLINE void * | vl_malloc (vl_size n) |
Call customizable malloc function. | |
VL_INLINE void * | vl_realloc (void *ptr, vl_size n) |
Call customizable resize function. | |
VL_INLINE void * | vl_calloc (vl_size n, vl_size size) |
Call customizable calloc function. | |
VL_INLINE void | vl_free (void *ptr) |
Call customizable free function. | |
void | vl_set_printf_func (int(*printf_func)(char const *str,...)) |
Call user-customizable printf function. | |
Error handling | |
#define | VL_ERR_MSG_LEN 1024 |
Error description maximum length. | |
#define | VL_ERR_OK 0 |
#define | VL_ERR_OVERFLOW 1 |
#define | VL_ERR_ALLOC 2 |
#define | VL_ERR_BAD_ARG 3 |
#define | VL_ERR_IO 4 |
#define | VL_ERR_EOF 5 |
#define | VL_ERR_NO_MORE 5 |
int | vl_err_no |
Last error code. | |
char | vl_err_msg [VL_ERR_MSG_LEN] |
Last error description. | |
Endianness detection and conversions | |
#define | VL_LITTLE_ENDIAN 0 |
#define | VL_BIG_ENDIAN 1 |
#define | VL_ENDIANNESS VL_BIG_ENDIAN |
Host endianness. | |
VL_INLINE int | vl_get_endianness () |
Get endianness. | |
VL_INLINE void | vl_adapt_endianness_8 (void *dst, void *src) |
Change endianness of 8-byte value if required. | |
VL_INLINE void | vl_adapt_endianness_4 (void *dst, void *src) |
Change endianness of 4-byte value if required. | |
VL_INLINE void | vl_adapt_endianness_2 (void *dst, void *src) |
Change endianness of 2-byte value if required. | |
Defines | |
#define | VL_VERSION_STRING "0.1" |
Library version string. | |
#define | VL_INLINE static __inline__ |
Inline function declaration. | |
#define | VL_STRINGIFY_(x) # x |
Stringify argument helper. | |
#define | VL_STRINGIFY(x) VL_STRINGIFY_(x) |
Stringify macro. | |
#define | VL_BIG_INT 2147483647 |
Big integer. | |
#define | VL_SMALL_INT (- VL_BIG_INT - 1) |
Small integer. | |
#define | VL_LOG_OF_2 0.693147180559945 |
Logarithm of 2. | |
#define | VL_NAN_F (vl_nan_f.value) |
Single NaN (not signaling). | |
#define | VL_INFINITY_F (vl_infinity_f.value) |
Single Infinity (not signaling). | |
#define | VL_NAN_D (vl_nan_d.value) |
Double NaN (not signaling). | |
#define | VL_INFINITY_D (vl_infinity_d.value) |
Double Infinity (not signaling). | |
Common operations | |
#define | VL_MIN(x, y) (((x)<(y))?(x):(y)) |
Min operation. | |
#define | VL_MAX(x, y) (((x)>(y))?(x):(y)) |
Max operation. | |
#define | VL_SHIFT_LEFT(x, n) (((n)>=0)?((x)<<(n)):((x)>>-(n))) |
Signed left shift operation. | |
Typedefs | |
Atomic data types | |
typedef long long | vl_int64 |
typedef int | vl_int32 |
typedef short | vl_int16 |
typedef char | vl_int8 |
typedef long long unsigned | vl_uint64 |
typedef int unsigned | vl_uint32 |
typedef short unsigned | vl_uint16 |
typedef char unsigned | vl_uint8 |
typedef int | vl_int |
typedef unsigned int | vl_uint |
typedef float | vl_single |
typedef double | vl_double |
typedef unsigned int | vl_uidx |
typedef size_t | vl_size |
typedef int | vl_bool |
Functions | |
char const * | vl_get_version_string () |
Get version string. | |
Variables | |
int(* | vl_printf_func )(char const *format,...) |
Customizable printf function pointer. | |
void *(* | vl_malloc_func )(vl_size) |
Customizable malloc function pointer. | |
void *(* | vl_realloc_func )(void *, vl_size) |
Customizable realloc function pointer. | |
void *(* | vl_calloc_func )(vl_size, vl_size) |
Customizable calloc function pointer. | |
void(* | vl_free_func )(void *) |
Customizable free function pointer. |
Use the function vl_get_endianness() to detect endianness. To serialize/deserialize data in big endian (network) order, call the functions vl_adapt_endianness_8(), vl_adapt_endianness_4(), vl_adapt_endianness_2() after reading and before writing (the functions change edinanness only if the architecture is little endian and do nothing otherwise).
#define VL_BIG_ENDIAN 1 |
big endian.
#define VL_ENDIANNESS VL_BIG_ENDIAN |
This macro is equal to VL_BIG_ENDIAN or VL_LITTLE_ENDIAN depending on the endianness of the host.
#define VL_ERR_ALLOC 2 |
Resource allocation error
#define VL_ERR_BAD_ARG 3 |
Bad argument or illegal data error
#define VL_ERR_EOF 5 |
End-of-file or end-of-sequence error
#define VL_ERR_IO 4 |
Input/output error
#define VL_ERR_MSG_LEN 1024 |
This is the size of the vl_err_msg buffer.
#define VL_ERR_NO_MORE 5 |
End-of-sequence
#define VL_ERR_OK 0 |
No error
#define VL_ERR_OVERFLOW 1 |
Buffer overflow error
#define VL_LITTLE_ENDIAN 0 |
little endian.
#define VL_MAX | ( | x, | |||
y | ) | (((x)>(y))?(x):(y)) |
x | value. | |
y | value. |
#define VL_MIN | ( | x, | |||
y | ) | (((x)<(y))?(x):(y)) |
x | value | |
y | value |
#define VL_PRINT | ( | string | ) | ((*vl_printf_func)(string)) |
string | string to print. |
printf
. #define VL_PRINTF | ( | format, | |||
... | ) | ((*vl_printf_func)((format), __VA_ARGS__)) |
format | format string. | |
... | printf variable arguments. |
printf
.
printf
. #define VL_SHIFT_LEFT | ( | x, | |||
n | ) | (((n)>=0)?((x)<<(n)):((x)>>-(n))) |
The macro is equivalent to the builtin <<
operator, but it supports negative shifts too.
x | value. | |
n | number of shift positions. |
x
<< n . #define VL_STRINGIFY | ( | x | ) | VL_STRINGIFY_(x) |
x | macro to stringify |
#define A x.y.z printf(VL_STRINGIFY(A)) ;
x.y.z
.
#define VL_STRINGIFY_ | ( | x | ) | # x |
typedef int vl_bool |
boolean
typedef double vl_double |
double precision float.
typedef int vl_int |
integer.
typedef short vl_int16 |
signed 16-bit integer.
typedef int vl_int32 |
signed 32-bit integer.
typedef long long vl_int64 |
signed 64-bit integer.
typedef char vl_int8 |
signed 8-bit integer.
typedef float vl_single |
single precision float.
typedef size_t vl_size |
size data type.
typedef unsigned int vl_uidx |
unsigned index data type.
typedef unsigned int vl_uint |
unsigned integer.
typedef short unsigned vl_uint16 |
unsigned 16-bit integer.
typedef int unsigned vl_uint32 |
unsigned 32-bit integer.
typedef long long unsigned vl_uint64 |
unsigned 64-bit integer.
typedef char unsigned vl_uint8 |
unsigned 8-bit integer.
VL_INLINE void vl_adapt_endianness_2 | ( | void * | dst, | |
void * | src | |||
) |
dst | destination 2-byte buffer. | |
src | source 2-byte bufffer. |
VL_INLINE void vl_adapt_endianness_4 | ( | void * | dst, | |
void * | src | |||
) |
dst | destination 4-byte buffer. | |
src | source 4-byte bufffer. |
VL_INLINE void vl_adapt_endianness_8 | ( | void * | dst, | |
void * | src | |||
) |
dst | destination 8-byte buffer. | |
src | source 8-byte bufffer. |
n | size of each element in byte. | |
size | size of the array to allocate (number of elements). |
calloc
.
calloc
. VL_INLINE void vl_free | ( | void * | ptr | ) |
ptr | buffer to free. |
free
.
VL_INLINE int vl_get_endianness | ( | ) |
VL_BIG_ENDIAN
or VL_LITTLE_ENDIAN depending on the host endianness. char const* vl_get_version_string | ( | ) |
VL_INLINE void * vl_malloc | ( | vl_size | n | ) |
n | number of bytes to allocate. |
malloc
.
malloc
VL_INLINE void * vl_realloc | ( | void * | ptr, | |
vl_size | n | |||
) |
ptr | buffer to reallocate. | |
n | number of bytes to allocate. |
realloc
.
realloc
. void vl_set_alloc_func | ( | void *(*)(vl_size) | malloc_func, | |
void *(*)(void *, vl_size) | realloc_func, | |||
void *(*)(vl_size, vl_size) | calloc_func, | |||
void(*)(void *) | free_func | |||
) |
malloc_func | pointer to malloc . | |
realloc_func | pointer to realloc . | |
calloc_func | pointer to calloc . | |
free_func | pointer to free . |
void vl_set_printf_func | ( | int(*)(char const *str,...) | printf_func | ) |
format | format string. | |
... | printf variable arguments. |
printf
.
printf
.
void*(* vl_calloc_func)(vl_size, vl_size) |
For internal use only.
void(* vl_free_func)(void *) |
For internal use only.
void*(* vl_malloc_func)(vl_size) |
For internal use only.
int(* vl_printf_func)(char const *format,...) |
For internal use only.
void*(* vl_realloc_func)(void *, vl_size) |
For internal use only.