1
0
mirror of https://github.com/facebook/zstd.git synced 2025-08-08 17:22:10 +03:00

add support for setting compression level through environment variable ZSTD_CLEVEL

This commit is contained in:
Yi Jin
2018-12-19 13:26:27 -08:00
parent 517d8c984c
commit 5324b1e386

View File

@@ -28,6 +28,7 @@
#include "platform.h" /* IS_CONSOLE, PLATFORM_POSIX_VERSION */ #include "platform.h" /* IS_CONSOLE, PLATFORM_POSIX_VERSION */
#include "util.h" /* UTIL_HAS_CREATEFILELIST, UTIL_createFileList */ #include "util.h" /* UTIL_HAS_CREATEFILELIST, UTIL_createFileList */
#include <stdio.h> /* fprintf(), stdin, stdout, stderr */ #include <stdio.h> /* fprintf(), stdin, stdout, stderr */
#include <stdlib.h> /* getenv */
#include <string.h> /* strcmp, strlen */ #include <string.h> /* strcmp, strlen */
#include <errno.h> /* errno */ #include <errno.h> /* errno */
#include "fileio.h" /* stdinmark, stdoutmark, ZSTD_EXTENSION */ #include "fileio.h" /* stdinmark, stdoutmark, ZSTD_EXTENSION */
@@ -452,6 +453,28 @@ static void printVersion(void)
#endif #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; 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; } #define CLEAN_RETURN(i) { operationResult = (i); goto _end; }
@@ -493,7 +516,7 @@ int main(int argCount, const char* argv[])
size_t blockSize = 0; size_t blockSize = 0;
zstd_operation_mode operation = zom_compress; zstd_operation_mode operation = zom_compress;
ZSTD_compressionParameters compressionParams; ZSTD_compressionParameters compressionParams;
int cLevel = ZSTDCLI_CLEVEL_DEFAULT; int cLevel = init_cLevel();
int cLevelLast = -1000000000; int cLevelLast = -1000000000;
unsigned recursive = 0; unsigned recursive = 0;
unsigned memLimit = 0; unsigned memLimit = 0;