From: Yann Collet Date: Thu, 7 Jan 2021 18:37:27 +0000 (-0800) Subject: Added library version check X-Git-Tag: v1.4.9^2~30^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3324e87cff43bdb0ebfe63375264cad60da56046;p=thirdparty%2Fzstd.git Added library version check --- diff --git a/programs/Makefile b/programs/Makefile index 48a60ad0f..3eb658f42 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -289,7 +289,7 @@ zstd-noxz : LZMALD := zstd-noxz : LZMA_MSG := - xz/lzma support is disabled zstd-noxz : zstd -## zstd-dll: zstd executable linked to dynamic library libzstd (must already exist) +## zstd-dll: zstd executable linked to dynamic library libzstd (must have same version) .PHONY: zstd-dll zstd-dll : LDFLAGS+= -L$(ZSTDDIR) zstd-dll : LDLIBS += -lzstd diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 1b0b6761d..a46878375 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -103,6 +103,24 @@ typedef enum { cover, fastCover, legacy } dictType; static int g_displayLevel = DISPLAY_LEVEL_DEFAULT; /* 0 : no display, 1: errors, 2 : + result + interaction + warnings, 3 : + progression, 4 : + information */ +/*-************************************ +* Check Version (when CLI linked to dynamic library) +**************************************/ + +/* Due to usage of experimental symbols and capabilities by the CLI, + * the CLI must be linked against a dynamic library of same version */ +static void checkLibVersion(void) +{ + if (strcmp(ZSTD_VERSION_STRING, ZSTD_versionString())) { + DISPLAYLEVEL(1, "Error : incorrect library version (expecting : %s ; actual : %s ) \n", + ZSTD_VERSION_STRING, ZSTD_versionString()); + DISPLAYLEVEL(1, "Please update library to version %s, or use stand-alone zstd binary \n", + ZSTD_VERSION_STRING); + exit(1); + } +} + + /*-************************************ * Command Line **************************************/ @@ -753,6 +771,7 @@ int main(int const argCount, const char* argv[]) /* init */ + checkLibVersion(); (void)recursive; (void)cLevelLast; /* not used when ZSTD_NOBENCH set */ (void)memLimit; assert(argCount >= 1); @@ -1281,15 +1300,15 @@ int main(int const argCount, const char* argv[]) DISPLAY("error : can't use --patch-from=# on multiple files \n"); CLEAN_RETURN(1); } - - /* No status message in pipe mode (stdin - stdout) */ + + /* No status message in pipe mode (stdin - stdout) */ hasStdout = outFileName && !strcmp(outFileName,stdoutmark); if (hasStdout && (g_displayLevel==2)) g_displayLevel=1; /* IO Stream/File */ FIO_setHasStdoutOutput(fCtx, hasStdout); - FIO_setNbFilesTotal(fCtx, (int)filenames->tableSize); + FIO_setNbFilesTotal(fCtx, (int)filenames->tableSize); FIO_determineHasStdinInput(fCtx, filenames); FIO_setNotificationLevel(g_displayLevel); FIO_setPatchFromMode(prefs, patchFromDictFileName != NULL);