diff --git a/contrib/adaptive-compression/multi.c b/contrib/adaptive-compression/multi.c index 41fd9af4..78d9ca15 100644 --- a/contrib/adaptive-compression/multi.c +++ b/contrib/adaptive-compression/multi.c @@ -367,18 +367,28 @@ static void printStats(cStat_t stats) DISPLAY("# times waited on job Write: %u\n\n", stats.waitWrite); } -static int compressFilename(const char* const srcFilename, const char* const dstFilename) +static int compressFilename(const char* const srcFilename, const char* const dstFilenameOrNull) { BYTE* const src = malloc(FILE_CHUNK_SIZE); unsigned const stdinUsed = !strcmp(srcFilename, stdinmark); FILE* const srcFile = stdinUsed ? stdin : fopen(srcFilename, "rb"); - const char* const outFilename = (stdinUsed && !dstFilename) ? stdoutmark : dstFilename; + const char* const outFilenameIntermediate = (stdinUsed && !dstFilenameOrNull) ? stdoutmark : dstFilenameOrNull; + const char* outFilename = outFilenameIntermediate; + char fileAndSuffix[MAX_PATH]; size_t const numJobs = MAX_NUM_JOBS; int ret = 0; adaptCCtx* ctx = NULL; UTIL_getTime(&g_startTime); g_streamedSize = 0; + if (!outFilenameIntermediate) { + if (snprintf(fileAndSuffix, MAX_PATH, "%s.zst", srcFilename) + 1 > MAX_PATH) { + DISPLAY("Error: output filename is too long\n"); + ret = 1; + goto cleanup; + } + outFilename = fileAndSuffix; + } /* checking for errors */ if (!srcFilename || !outFilename || !src || !srcFile) { @@ -452,15 +462,10 @@ static int compressFilenames(const char** filenameTable, unsigned numFiles, unsi { int ret = 0; unsigned fileNum; - char outFile[MAX_PATH]; for (fileNum=0; fileNum MAX_PATH) { - DISPLAY("Error: output filename is too long\n"); - return 1; - } if (!forceStdout) { - ret |= compressFilename(filename, outFile); + ret |= compressFilename(filename, NULL); } else { ret |= compressFilename(filename, stdoutmark); diff --git a/contrib/adaptive-compression/run.sh b/contrib/adaptive-compression/run.sh index 67814ec1..3c40969e 100755 --- a/contrib/adaptive-compression/run.sh +++ b/contrib/adaptive-compression/run.sh @@ -151,6 +151,12 @@ echo "Running Tests With Multiple Files > stdout" zstd -d tmp.zst rm tmp* +echo "Running single test without output filename" +./multi tests/test2048.pdf -p +zstd -d tests/test2048.pdf.zst -o tmp +diff tmp tests/test2048.pdf +rm tmp* + echo "finished with tests" make clean