cgul_endian.h File Reference

convert between big-endian and little-endian formats More...

#include "cgul_common.h"
#include "cgul_exception.h"
Include dependency graph for cgul_endian.h:
This graph shows which files directly or indirectly include this file:

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)
 

Detailed Description

Cconvert between big-endian and little-endian formats.

Author
Paul Serice

Function Documentation

§ cgul_endian__is_big_endian()

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.

Parameters
[in]cexc-style exception
Returns
whether the host is big-endian

Referenced by cgul_endian_cxx::is_big_endian().

§ cgul_endian__is_little_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.

Parameters
[in]cexc-style exception
Returns
whether the host is little endian

Referenced by cgul_endian_cxx::is_little_endian().

§ cgul_endian__swap()

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));
        ...
    }
Parameters
[in]cexc-style exception
[in,out]valuevalue
[in]value_sizesize of value
See also
cgul_int

Referenced by cgul_endian_cxx::swap().