commit 84905a4df0448257e846e97eeed8a4d4f3e275bc
parent f5b873553831a9721b5d59c335b5217ec817ce48
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Sat, 18 May 2019 13:30:07 +0300
http_chunked_compression example: clarify and improve readability
Diffstat:
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git 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