Use configure-time constant for the host's endianness
This commit is contained in:
parent
d4019706a8
commit
828f970da5
@ -35,6 +35,11 @@ set(ALL_SRC_FILES ${ALL_SRC_FILES})
|
||||
# Find bit size of the target architecture
|
||||
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
|
||||
|
||||
# Test if host's architecture is big-endian
|
||||
include(TestBigEndian)
|
||||
test_big_endian(GMIO_HOST_IS_BIG_ENDIAN)
|
||||
|
||||
# Find available C99 features
|
||||
if(NOT BUILD_STRICT_C90)
|
||||
# Have <stdint.h> ?
|
||||
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
||||
|
@ -27,6 +27,8 @@
|
||||
|
||||
#cmakedefine GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC
|
||||
|
||||
#cmakedefine GMIO_HOST_IS_BIG_ENDIAN
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# if defined(__i386__) || defined(__ppc__)
|
||||
# define GMIO_TARGET_ARCH_BIT_SIZE 32
|
||||
|
@ -33,6 +33,14 @@ enum gmio_endianness
|
||||
|
||||
typedef enum gmio_endianness gmio_endianness_t;
|
||||
|
||||
enum {
|
||||
#ifdef GMIO_HOST_IS_BIG_ENDIAN
|
||||
GMIO_HOST_ENDIANNESS = GMIO_BIG_ENDIAN
|
||||
#else
|
||||
GMIO_HOST_ENDIANNESS = GMIO_LITTLE_ENDIAN
|
||||
#endif
|
||||
};
|
||||
|
||||
GMIO_C_LINKAGE_BEGIN
|
||||
|
||||
/*! Returns endianness (byte order) of the host's CPU architecture */
|
||||
|
@ -72,10 +72,8 @@ int gmio_stlb_read(
|
||||
const gmio_stlb_read_options_t* options)
|
||||
{
|
||||
/* Constants */
|
||||
const gmio_endianness_t host_byte_order =
|
||||
gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order =
|
||||
options != NULL ? options->byte_order : host_byte_order;
|
||||
options != NULL ? options->byte_order : GMIO_HOST_ENDIANNESS;
|
||||
const uint32_t max_facet_count_per_read =
|
||||
trsf != NULL ?
|
||||
gmio_size_to_uint32(
|
||||
@ -92,7 +90,7 @@ int gmio_stlb_read(
|
||||
return error;
|
||||
|
||||
/* Initialize rparams */
|
||||
if (host_byte_order != byte_order)
|
||||
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||
rparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||
|
||||
/* Read header */
|
||||
@ -107,7 +105,7 @@ int gmio_stlb_read(
|
||||
return GMIO_STLB_READ_FACET_COUNT_ERROR;
|
||||
|
||||
memcpy(&total_facet_count, trsf->buffer, sizeof(uint32_t));
|
||||
if (host_byte_order != byte_order)
|
||||
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
||||
|
||||
/* Callback to notify triangle count and header data */
|
||||
|
@ -73,10 +73,8 @@ int gmio_stlb_write(
|
||||
const gmio_stlb_write_options_t* options)
|
||||
{
|
||||
/* Constants */
|
||||
const gmio_endianness_t host_byte_order =
|
||||
gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order =
|
||||
options != NULL ? options->byte_order : host_byte_order;
|
||||
options != NULL ? options->byte_order : GMIO_HOST_ENDIANNESS;
|
||||
const uint8_t* header_data =
|
||||
options != NULL ? options->header_data : NULL;
|
||||
const uint32_t facet_count =
|
||||
@ -93,7 +91,7 @@ int gmio_stlb_write(
|
||||
return error;
|
||||
|
||||
/* Initialize wparams */
|
||||
if (host_byte_order != byte_order)
|
||||
if (byte_order != GMIO_HOST_ENDIANNESS)
|
||||
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||
wparams.facet_count = gmio_size_to_uint32(
|
||||
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||
|
Loading…
Reference in New Issue
Block a user