[examples] Update streaming_compression to the new API

This commit is contained in:
Nick Terrell
2019-03-23 15:59:26 -07:00
committed by Nick Terrell
parent 0c7668cd06
commit f5cbee988b
2 changed files with 81 additions and 28 deletions
+28
View File
@@ -20,6 +20,7 @@
#include <errno.h> // errno
#include <assert.h> // assert
#include <sys/stat.h> // stat
#include <zstd.h>
/*
* Define the returned error code from utility functions.
@@ -204,4 +205,31 @@ static void saveFile_orDie(const char* fileName, const void* buff, size_t buffSi
}
}
/*! CHECK
* Check that the condition holds. If it doesn't print a message and die.
*/
#define CHECK(cond, ...) \
do { \
if (!(cond)) { \
fprintf(stderr, \
"%s:%d CHECK(%s) failed: ", \
__FILE__, \
__LINE__, \
#cond); \
fprintf(stderr, "" __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(1); \
} \
} while (0)
/*! CHECK_ZSTD
* Check the zstd error code and die if an error occurred after printing a
* message.
*/
#define CHECK_ZSTD(fn, ...) \
do { \
size_t const err = (fn); \
CHECK(!ZSTD_isError(err), "%s", ZSTD_getErrorName(err)); \
} while (0)
#endif