- zstd source repository : https://github.com/Cyan4973/zstd
*/
-#include <stdio.h> /* fprintf */
#include <stdarg.h> /* va_list */
#include <zlib.h>
#include "zstd_zlibwrapper.h"
#define LOG_WRAPPER(...) // printf(__VA_ARGS__)
-#define FINISH_WITH_ERR(msg) { \
- fprintf(stderr, "ERROR: %s\n", msg); \
+#define FINISH_WITH_GZ_ERR(msg) { \
+ (void)msg; \
+ return Z_MEM_ERROR; \
+}
+
+#define FINISH_WITH_ERR(strm, message) { \
+ strm->msg = message; \
return Z_MEM_ERROR; \
}
#define FINISH_WITH_NULL_ERR(msg) { \
- fprintf(stderr, "ERROR: %s\n", msg); \
+ (void)msg; \
return NULL; \
}
strm->avail_in -= srcSize;
}
- if (flush == Z_FULL_FLUSH) FINISH_WITH_ERR("Z_FULL_FLUSH is not supported!");
+ if (flush == Z_FULL_FLUSH) FINISH_WITH_ERR(strm, "Z_FULL_FLUSH is not supported!");
if (flush == Z_FINISH || flush == Z_FULL_FLUSH) {
size_t bytesLeft;
{
if (!g_useZSTD)
return deflateCopy(dest, source);
- FINISH_WITH_ERR("deflateCopy is not supported!");
+ FINISH_WITH_ERR(source, "deflateCopy is not supported!");
}
{
if (!g_useZSTD)
return deflateReset(strm);
- FINISH_WITH_ERR("deflateReset is not supported!");
+ FINISH_WITH_ERR(strm, "deflateReset is not supported!");
}
{
if (!g_useZSTD)
return deflateTune(strm, good_length, max_lazy, nice_length, max_chain);
- FINISH_WITH_ERR("deflateTune is not supported!");
+ FINISH_WITH_ERR(strm, "deflateTune is not supported!");
}
{
if (!g_useZSTD)
return deflatePending(strm, pending, bits);
- FINISH_WITH_ERR("deflatePending is not supported!");
+ FINISH_WITH_ERR(strm, "deflatePending is not supported!");
}
#endif
{
if (!g_useZSTD)
return deflatePrime(strm, bits, value);
- FINISH_WITH_ERR("deflatePrime is not supported!");
+ FINISH_WITH_ERR(strm, "deflatePrime is not supported!");
}
{
if (!g_useZSTD)
return deflateSetHeader(strm, head);
- FINISH_WITH_ERR("deflateSetHeader is not supported!");
+ FINISH_WITH_ERR(strm, "deflateSetHeader is not supported!");
}
{
if (!strm->reserved)
return inflateGetDictionary(strm, dictionary, dictLength);
- FINISH_WITH_ERR("inflateGetDictionary is not supported!");
+ FINISH_WITH_ERR(strm, "inflateGetDictionary is not supported!");
}
#endif
{
if (!g_useZSTD)
return inflateCopy(dest, source);
- FINISH_WITH_ERR("inflateCopy is not supported!");
+ FINISH_WITH_ERR(source, "inflateCopy is not supported!");
}
{
if (!strm->reserved)
return inflateReset(strm);
- FINISH_WITH_ERR("inflateReset is not supported!");
+ FINISH_WITH_ERR(strm, "inflateReset is not supported!");
}
{
if (!strm->reserved)
return inflateReset2(strm, windowBits);
- FINISH_WITH_ERR("inflateReset2 is not supported!");
+ FINISH_WITH_ERR(strm, "inflateReset2 is not supported!");
}
#endif
{
if (!strm->reserved)
return inflateMark(strm);
- FINISH_WITH_ERR("inflateMark is not supported!");
+ FINISH_WITH_ERR(strm, "inflateMark is not supported!");
}
#endif
{
if (!strm->reserved)
return inflatePrime(strm, bits, value);
- FINISH_WITH_ERR("inflatePrime is not supported!");
+ FINISH_WITH_ERR(strm, "inflatePrime is not supported!");
}
{
if (!strm->reserved)
return inflateGetHeader(strm, head);
- FINISH_WITH_ERR("inflateGetHeader is not supported!");
+ FINISH_WITH_ERR(strm, "inflateGetHeader is not supported!");
}
{
if (!strm->reserved)
return inflateBackInit_(strm, windowBits, window, version, stream_size);
- FINISH_WITH_ERR("inflateBackInit is not supported!");
+ FINISH_WITH_ERR(strm, "inflateBackInit is not supported!");
}
{
if (!strm->reserved)
return inflateBack(strm, in, in_desc, out, out_desc);
- FINISH_WITH_ERR("inflateBack is not supported!");
+ FINISH_WITH_ERR(strm, "inflateBack is not supported!");
}
{
if (!strm->reserved)
return inflateBackEnd(strm);
- FINISH_WITH_ERR("inflateBackEnd is not supported!");
+ FINISH_WITH_ERR(strm, "inflateBackEnd is not supported!");
}
{
if (!g_useZSTD)
return gzbuffer(file, size);
- FINISH_WITH_ERR("gzbuffer is not supported!");
+ FINISH_WITH_GZ_ERR("gzbuffer is not supported!");
}
{
if (!g_useZSTD)
return gzoffset(file);
- FINISH_WITH_ERR("gzoffset is not supported!");
+ FINISH_WITH_GZ_ERR("gzoffset is not supported!");
}
{
if (!g_useZSTD)
return gzclose_r(file);
- FINISH_WITH_ERR("gzclose_r is not supported!");
+ FINISH_WITH_GZ_ERR("gzclose_r is not supported!");
}
{
if (!g_useZSTD)
return gzclose_w(file);
- FINISH_WITH_ERR("gzclose_w is not supported!");
+ FINISH_WITH_GZ_ERR("gzclose_w is not supported!");
}
#endif
{
if (!g_useZSTD)
return gzsetparams(file, level, strategy);
- FINISH_WITH_ERR("gzsetparams is not supported!");
+ FINISH_WITH_GZ_ERR("gzsetparams is not supported!");
}
{
if (!g_useZSTD)
return gzread(file, buf, len);
- FINISH_WITH_ERR("gzread is not supported!");
+ FINISH_WITH_GZ_ERR("gzread is not supported!");
}
{
if (!g_useZSTD)
return gzwrite(file, buf, len);
- FINISH_WITH_ERR("gzwrite is not supported!");
+ FINISH_WITH_GZ_ERR("gzwrite is not supported!");
}
// printf("gzprintf ret=%d\n", ret);
return ret;
}
- FINISH_WITH_ERR("gzprintf is not supported!");
+ FINISH_WITH_GZ_ERR("gzprintf is not supported!");
}
{
if (!g_useZSTD)
return gzputs(file, s);
- FINISH_WITH_ERR("gzputs is not supported!");
+ FINISH_WITH_GZ_ERR("gzputs is not supported!");
}
{
if (!g_useZSTD)
return gzputc(file, c);
- FINISH_WITH_ERR("gzputc is not supported!");
+ FINISH_WITH_GZ_ERR("gzputc is not supported!");
}
{
if (!g_useZSTD)
return gzgetc(file);
- FINISH_WITH_ERR("gzgetc is not supported!");
+ FINISH_WITH_GZ_ERR("gzgetc is not supported!");
}
{
if (!g_useZSTD)
return gzungetc(c, file);
- FINISH_WITH_ERR("gzungetc is not supported!");
+ FINISH_WITH_GZ_ERR("gzungetc is not supported!");
}
{
if (!g_useZSTD)
return gzflush(file, flush);
- FINISH_WITH_ERR("gzflush is not supported!");
+ FINISH_WITH_GZ_ERR("gzflush is not supported!");
}
{
if (!g_useZSTD)
return gzseek(file, offset, whence);
- FINISH_WITH_ERR("gzseek is not supported!");
+ FINISH_WITH_GZ_ERR("gzseek is not supported!");
}
{
if (!g_useZSTD)
return gzrewind(file);
- FINISH_WITH_ERR("gzrewind is not supported!");
+ FINISH_WITH_GZ_ERR("gzrewind is not supported!");
}
{
if (!g_useZSTD)
return gztell(file);
- FINISH_WITH_ERR("gztell is not supported!");
+ FINISH_WITH_GZ_ERR("gztell is not supported!");
}
{
if (!g_useZSTD)
return gzeof(file);
- FINISH_WITH_ERR("gzeof is not supported!");
+ FINISH_WITH_GZ_ERR("gzeof is not supported!");
}
{
if (!g_useZSTD)
return gzdirect(file);
- FINISH_WITH_ERR("gzdirect is not supported!");
+ FINISH_WITH_GZ_ERR("gzdirect is not supported!");
}
{
if (!g_useZSTD)
return gzclose(file);
- FINISH_WITH_ERR("gzclose is not supported!");
+ FINISH_WITH_GZ_ERR("gzclose is not supported!");
}