From: Yi Jin Date: Wed, 19 Dec 2018 21:26:27 +0000 (-0800) Subject: add support for setting compression level through environment variable ZSTD_CLEVEL X-Git-Tag: v1.3.8~14^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5324b1e386c33e25450f8aab57930abd88bb8f39;p=thirdparty%2Fzstd.git add support for setting compression level through environment variable ZSTD_CLEVEL --- diff --git a/programs/zstdcli.c b/programs/zstdcli.c index e69661d5e..9737ae021 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -28,6 +28,7 @@ #include "platform.h" /* IS_CONSOLE, PLATFORM_POSIX_VERSION */ #include "util.h" /* UTIL_HAS_CREATEFILELIST, UTIL_createFileList */ #include /* fprintf(), stdin, stdout, stderr */ +#include /* getenv */ #include /* strcmp, strlen */ #include /* errno */ #include "fileio.h" /* stdinmark, stdoutmark, ZSTD_EXTENSION */ @@ -452,6 +453,28 @@ static void printVersion(void) #endif } +/* Environment variables for parameter setting */ +#define ENV_CLEVEL "ZSTD_CLEVEL" + +/* functions that pick up environment variables */ +int init_cLevel() { + const char *env = getenv(ENV_CLEVEL); + if (env) { + int sign = 1; + if (*env == '-') { + sign = -1; + env++; + } else if (*env == '+') { + env++; + } + + if ((*env>='0') && (*env<='9')) + return sign * readU32FromChar(&env); + } + + return ZSTDCLI_CLEVEL_DEFAULT; +} + typedef enum { zom_compress, zom_decompress, zom_test, zom_bench, zom_train, zom_list } zstd_operation_mode; #define CLEAN_RETURN(i) { operationResult = (i); goto _end; } @@ -493,7 +516,7 @@ int main(int argCount, const char* argv[]) size_t blockSize = 0; zstd_operation_mode operation = zom_compress; ZSTD_compressionParameters compressionParams; - int cLevel = ZSTDCLI_CLEVEL_DEFAULT; + int cLevel = init_cLevel(); int cLevelLast = -1000000000; unsigned recursive = 0; unsigned memLimit = 0;