diff options
author | David Robillard <d@drobilla.net> | 2023-04-03 08:51:58 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-04-05 09:45:15 -0400 |
commit | b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616 (patch) | |
tree | 538dc4c909648d45d91a33008b797ba0eccc2de7 /src/byte_sink.h | |
parent | f93c3fdd6c7d6ca61bec55d3c1ffae7e7c793913 (diff) | |
download | serd-b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616.tar.gz serd-b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616.tar.bz2 serd-b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616.zip |
Improve writer error handling
Diffstat (limited to 'src/byte_sink.h')
-rw-r--r-- | src/byte_sink.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/byte_sink.h b/src/byte_sink.h index ed0f65b4..65b5eb12 100644 --- a/src/byte_sink.h +++ b/src/byte_sink.h @@ -33,13 +33,18 @@ serd_byte_sink_new(SerdSink sink, void* stream, size_t block_size) return bsink; } -static inline void +static inline SerdStatus serd_byte_sink_flush(SerdByteSink* bsink) { if (bsink->block_size > 1 && bsink->size > 0) { - bsink->sink(bsink->buf, bsink->size, bsink->stream); - bsink->size = 0; + const size_t size = bsink->size; + const size_t n_out = bsink->sink(bsink->buf, size, bsink->stream); + bsink->size = 0; + + return (n_out != size) ? SERD_ERR_BAD_WRITE : SERD_SUCCESS; } + + return SERD_SUCCESS; } static inline void |