gmio_stl: refactor gmio_stlb_infos_get()

This commit is contained in:
Hugues Delorme 2016-01-07 17:12:58 +01:00
parent bdb02a9d8b
commit b0803b0a7b

View File

@ -25,15 +25,17 @@ int gmio_stlb_infos_get(
enum gmio_endianness byte_order, enum gmio_endianness byte_order,
unsigned flags) unsigned flags)
{ {
struct gmio_stl_infos* infos = &args->infos;
int error = GMIO_ERROR_OK;
if (flags != 0) { if (flags != 0) {
uint8_t buff[GMIO_STLB_HEADER_SIZE + sizeof(uint32_t)]; struct gmio_stl_infos* infos = &args->infos;
if (gmio_stream_read(&args->stream, buff, 1, sizeof(buff))
== sizeof(buff))
{
uint32_t facet_count = 0; uint32_t facet_count = 0;
uint8_t buff[GMIO_STLB_HEADER_SIZE + sizeof(uint32_t)];
{ /* Read header and facet count into buff */
const size_t read_size =
gmio_stream_read(&args->stream, buff, 1, sizeof(buff));
if (read_size != sizeof(buff))
return GMIO_ERROR_STREAM;
}
memcpy(&facet_count, buff + GMIO_STLB_HEADER_SIZE, sizeof(uint32_t)); memcpy(&facet_count, buff + GMIO_STLB_HEADER_SIZE, sizeof(uint32_t));
if (byte_order != GMIO_ENDIANNESS_HOST) if (byte_order != GMIO_ENDIANNESS_HOST)
@ -50,10 +52,6 @@ int gmio_stlb_infos_get(
+ facet_count * GMIO_STLB_TRIANGLE_RAWSIZE; + facet_count * GMIO_STLB_TRIANGLE_RAWSIZE;
} }
} }
else {
error = GMIO_ERROR_STREAM;
}
}
return error; return GMIO_ERROR_OK;
} }