diff --git a/Makefile b/Makefile index b11fc5774..9f5e1ebfa 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ else VOID = /dev/null endif -.PHONY: default all zlibwrapper zstdprogram clean install uninstall travis-install test clangtest gpptest armtest usan asan uasan +.PHONY: default all zlibwrapper zstdprogram zstd clean install uninstall travis-install test clangtest gpptest armtest usan asan uasan default: zstdprogram @@ -53,6 +53,8 @@ zstdprogram: $(MAKE) -C $(PRGDIR) cp $(PRGDIR)/zstd . +zstd: zstdprogram + zlibwrapper: $(MAKE) -C $(ZSTDDIR) all $(MAKE) -C $(ZWRAPDIR) all diff --git a/examples/simple_compression.c b/examples/simple_compression.c index 08c6c9f51..71a40c271 100644 --- a/examples/simple_compression.c +++ b/examples/simple_compression.c @@ -24,7 +24,7 @@ */ #include // malloc, exit -#include // printf +#include // fprintf, perror #include // strerror #include // errno #include // stat @@ -36,7 +36,7 @@ static off_t fsize_X(const char *filename) struct stat st; if (stat(filename, &st) == 0) return st.st_size; /* error */ - printf("stat: %s : %s \n", filename, strerror(errno)); + perror(filename); exit(1); } @@ -45,7 +45,7 @@ static FILE* fopen_X(const char *filename, const char *instruction) FILE* const inFile = fopen(filename, instruction); if (inFile) return inFile; /* error */ - printf("fopen: %s : %s \n", filename, strerror(errno)); + perror(filename); exit(2); } @@ -54,7 +54,7 @@ static void* malloc_X(size_t size) void* const buff = malloc(size); if (buff) return buff; /* error */ - printf("malloc: %s \n", strerror(errno)); + perror(NULL); exit(3); } @@ -65,7 +65,7 @@ static void* loadFile_X(const char* fileName, size_t* size) void* const buffer = malloc_X(buffSize); size_t const readSize = fread(buffer, 1, buffSize, inFile); if (readSize != (size_t)buffSize) { - printf("fread: %s : %s \n", fileName, strerror(errno)); + fprintf(stderr, "fread: %s : %s \n", fileName, strerror(errno)); exit(4); } fclose(inFile); @@ -79,12 +79,11 @@ static void saveFile_X(const char* fileName, const void* buff, size_t buffSize) FILE* const oFile = fopen_X(fileName, "wb"); size_t const wSize = fwrite(buff, 1, buffSize, oFile); if (wSize != (size_t)buffSize) { - printf("fwrite: %s : %s \n", fileName, strerror(errno)); + fprintf(stderr, "fwrite: %s : %s \n", fileName, strerror(errno)); exit(5); } - size_t const closeError = fclose(oFile); - if (closeError) { - printf("fclose: %s : %s \n", fileName, strerror(errno)); + if (fclose(oFile)) { + perror(fileName); exit(6); } } @@ -99,7 +98,7 @@ static void compress(const char* fname, const char* oname) size_t const cSize = ZSTD_compress(cBuff, cBuffSize, fBuff, fSize, 1); if (ZSTD_isError(cSize)) { - printf("error compressing %s : %s \n", fname, ZSTD_getErrorName(cSize)); + fprintf(stderr, "error compressing %s : %s \n", fname, ZSTD_getErrorName(cSize)); exit(7); } diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index 301b5f912..b5b0eb440 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -535,6 +535,7 @@ static size_t HUF_compress_internal ( { size_t const hSize = HUF_writeCTable (op, dstSize, CTable, maxSymbolValue, huffLog); if (HUF_isError(hSize)) return hSize; if (hSize + 12 >= srcSize) return 0; /* not useful to try compression */ + //static U64 totalHSize = 0; static U32 nbHSize = 0; totalHSize += hSize; nbHSize++; if ((nbHSize & 63) == 1) printf("average : %6.3f \n", (double)totalHSize / nbHSize); op += hSize; } diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 52dc72dd7..60af2e71c 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -657,7 +657,7 @@ static size_t ZSTD_compressLiterals (ZSTD_CCtx* zc, : HUF_compress2 (ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 12); } - if ((cLitSize==0) || (cLitSize >= srcSize - minGain)) + if ((cLitSize==0) | (cLitSize >= srcSize - minGain)) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize); if (cLitSize==1) return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize);