From 84905a4df0448257e846e97eeed8a4d4f3e275bc Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Sat, 18 May 2019 13:30:07 +0300 Subject: http_chunked_compression example: clarify and improve readability --- src/examples/http_chunked_compression.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/examples/http_chunked_compression.c b/src/examples/http_chunked_compression.c index 7ccd535e..6c55ef5f 100644 --- a/src/examples/http_chunked_compression.c +++ b/src/examples/http_chunked_compression.c @@ -88,30 +88,32 @@ read_cb (void *cls, uint64_t pos, char *mem, size_t size) struct Holder *holder = cls; void *src; void *buf; + ssize_t ret; src = malloc (size); if (NULL == src) return MHD_CONTENT_READER_END_WITH_ERROR; - size = fread (src, 1, size, holder->file); - if ((ssize_t) size < 0) + ret = fread (src, 1, size, holder->file); + if (ret < 0) { - size = MHD_CONTENT_READER_END_WITH_ERROR; + ret = MHD_CONTENT_READER_END_WITH_ERROR; goto done; } if (0 == size) { - size = MHD_CONTENT_READER_END_OF_STREAM; + ret = MHD_CONTENT_READER_END_OF_STREAM; goto done; } - if (MHD_YES != compress_buf (&holder->stream, src, size, &pos, &buf, &size, holder->buf)) - size = MHD_CONTENT_READER_END_WITH_ERROR; + if (MHD_YES != compress_buf (&holder->stream, src, ret, &pos, &buf, &size, holder->buf)) + ret = MHD_CONTENT_READER_END_WITH_ERROR; else { memcpy (mem, buf, size); + ret = size; } free (buf); /* Buf may be set even on error return. */ done: free (src); - return size; + return ret; } static void -- cgit v1.2.3