From 867cdc009880b27db34b1bd15dce5168c5739a8e Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 24 Jan 2013 11:29:51 +0100 Subject: [PATCH] libc: improve handling of stream error --- src/c/libstl/stlb_read.c | 9 +++++++-- src/c/stream.c | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/c/libstl/stlb_read.c b/src/c/libstl/stlb_read.c index 8e37ed3..1e8151e 100644 --- a/src/c/libstl/stlb_read.c +++ b/src/c/libstl/stlb_read.c @@ -70,8 +70,13 @@ int foug_stlb_read(foug_stlb_read_args_t args) while (foug_stlb_no_error(error) && accum_facet_count_read < total_facet_count) { const size_t facet_count_read = foug_stream_read(args.stream, buffer, FOUG_STLB_TRIANGLE_SIZE, buffer_facet_count); - error = foug_stream_error(args.stream) != 0 ? FOUG_STLB_READ_STREAM_ERROR : - FOUG_STLB_READ_NO_ERROR; + if (foug_stream_error(args.stream) != 0) + error = FOUG_STLB_READ_STREAM_ERROR; + else if (facet_count_read > 0) + error = FOUG_STLB_READ_NO_ERROR; + else + break; /* Exit if no facet to read */ + if (foug_stlb_no_error(error)) { uint32_t buffer_offset = 0; uint32_t i_facet; diff --git a/src/c/stream.c b/src/c/stream.c index 4d68a43..e665cde 100644 --- a/src/c/stream.c +++ b/src/c/stream.c @@ -58,10 +58,10 @@ static size_t foug_stream_stdio_write(foug_stream_t* stream, foug_stream_manip_t foug_stream_manip_stdio() { foug_stream_manip_t manip; - manip.at_end_func = &foug_stream_stdio_at_end; - manip.error_func = &foug_stream_stdio_error; - manip.read_func = &foug_stream_stdio_read; - manip.write_func = &foug_stream_stdio_write; + manip.at_end_func = foug_stream_stdio_at_end; + manip.error_func = foug_stream_stdio_error; + manip.read_func = foug_stream_stdio_read; + manip.write_func = foug_stream_stdio_write; return manip; }