int const allJobsCondError = pthread_cond_destroy(&ctx->allJobsCompleted_cond);
int const jobWriteMutexError = pthread_mutex_destroy(&ctx->jobWrite_mutex);
int const jobWriteCondError = pthread_cond_destroy(&ctx->jobWrite_cond);
- int const fileCloseError = ctx->dstFile != NULL ? fclose(ctx->dstFile) : 0;
+ int const fileCloseError = (ctx->dstFile != NULL && ctx->dstFile != stdout) ? fclose(ctx->dstFile) : 0;
if (ctx->jobs){
freeCompressionJobs(ctx);
free(ctx->jobs);
return ret;
}
-static int compressFilenames(const char** filenameTable, unsigned numFiles)
+static int compressFilenames(const char** filenameTable, unsigned numFiles, unsigned forceStdout)
{
int ret = 0;
unsigned fileNum;
DISPLAY("Error: output filename is too long\n");
return 1;
}
- ret |= compressFilename(filename, outFile);
+ if (!forceStdout) {
+ ret |= compressFilename(filename, outFile);
+ }
+ else {
+ ret |= compressFilename(filename, stdoutmark);
+ }
+
}
return ret;
}
const char** filenameTable = (const char**)malloc(argCount*sizeof(const char*));
unsigned filenameIdx = 0;
filenameTable[0] = stdinmark;
+ unsigned forceStdout = 0;
int ret = 0;
int argNum;
case 'p':
g_useProgressBar = 1;
break;
+ case 'c':
+ forceStdout = 1;
+ break;
default:
DISPLAY("Error: invalid argument provided\n");
ret = 1;
}
/* error checking with number of files */
- if (filenameIdx > 1 && outFilename != NULL) {
+ if (filenameIdx > 1 && (outFilename != NULL && strcmp(outFilename, stdoutmark))) {
DISPLAY("Error: multiple input files provided, cannot use specified output file\n");
ret = 1;
goto _main_exit;
ret |= compressFilename(filenameTable[0], outFilename);
}
else {
- ret |= compressFilenames(filenameTable, filenameIdx);
+ ret |= compressFilenames(filenameTable, filenameIdx, forceStdout);
}
_main_exit:
free(filenameTable);
diff tests/test1024.pdf tests/tmp1024
diff tests/test2048.pdf tests/tmp2048
+rm -f tests/*.zst tests/tmp*
echo "Running Args Tests"
./multi -h
./multi -i22 -p -s -otmp.zst tests/test2048.pdf
+rm tmp*
+
+echo "Running Tests With Multiple Files > stdout"
+./multi tests/* -c > tmp.zst
+zstd -d tmp.zst
+rm tmp*
+
echo "finished with tests"
make clean