convert between big-endian and little-endian formats More...
Functions | |
CGUL_BEGIN_C CGUL_EXPORT int | cgul_endian__is_big_endian (cgul_exception_t *cex) |
CGUL_EXPORT int | cgul_endian__is_little_endian (cgul_exception_t *cex) |
CGUL_EXPORT void | cgul_endian__swap (cgul_exception_t *cex, void *value, size_t value_size) |
Cconvert between big-endian and little-endian formats.
CGUL_BEGIN_C CGUL_EXPORT int cgul_endian__is_big_endian | ( | cgul_exception_t * | cex | ) |
Return whether the host is big endian. This is a fast run-time test, but calling it before each swap will adversely affect performance.
[in] | cex | c-style exception |
Referenced by cgul_endian_cxx::is_big_endian().
CGUL_EXPORT int cgul_endian__is_little_endian | ( | cgul_exception_t * | cex | ) |
Return whether the host is little endian. This is a fast run-time test, but calling it before each swap will adversely affect performance.
[in] | cex | c-style exception |
Referenced by cgul_endian_cxx::is_little_endian().
CGUL_EXPORT void cgul_endian__swap | ( | cgul_exception_t * | cex, |
void * | value, | ||
size_t | value_size | ||
) |
Byte swap the first value_size
bytes in the region of memory pointed to by value
. If value
is in big-endian format, it will be converted to little-endian format and vice versa.
The following example shows how to convert an unsigned, big-endian 32-bit integer to the host format (assuming the host is either big endian or little endian instead of one of the more exotic formats):
cgul_uint32_t value; ...
if (cgul_endian__is_little_endian(cex)) { ... cgul_endian__swap(cex, (char*)&value, sizeof(value)); ... }
[in] | cex | c-style exception |
[in,out] | value | value |
[in] | value_size | size of value |
Referenced by cgul_endian_cxx::swap().