summaryrefslogtreecommitdiffstats
path: root/programs/lz4io.c
diff options
context:
space:
mode:
authorFilipe Calasans <filipe.calasans@gmail.com>2020-02-07 22:52:25 (GMT)
committerFilipe Calasans <filipe.calasans@gmail.com>2020-02-08 01:03:13 (GMT)
commit781417a36997548c54c445c0e2e9634e69b0e0c6 (patch)
tree254a238d43dc87efec79f9b328d3f1831371b95a /programs/lz4io.c
parent8372862e0f7e072cb206e96c70f6e1a796b66fe6 (diff)
downloadlz4-781417a36997548c54c445c0e2e9634e69b0e0c6.zip
lz4-781417a36997548c54c445c0e2e9634e69b0e0c6.tar.gz
lz4-781417a36997548c54c445c0e2e9634e69b0e0c6.tar.bz2
Implement -m option with legacy format on cli
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r--programs/lz4io.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c
index ec6dc7f..7926b20 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -470,11 +470,59 @@ int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs, const char* input_
free(in_buff);
free(out_buff);
fclose(finput);
- fclose(foutput);
+ if (strcmp(output_filename,stdoutmark)) fclose(foutput); /* do not close stdout */
return 0;
}
+#define FNSPACE 30
+/* LZ4IO_compressMultipleFilenames_Legacy :
+ * This function is intentionally "hidden" (not published in .h)
+ * It generates multiple compressed streams using the old 'legacy' format */
+int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs,
+ const char** inFileNamesTable, int ifntSize,
+ const char* suffix,
+ int compressionLevel)
+{
+ int i;
+ int missed_files = 0;
+ char* dstFileName = (char*)malloc(FNSPACE);
+ size_t ofnSize = FNSPACE;
+ const size_t suffixSize = strlen(suffix);
+
+ if (dstFileName == NULL) return ifntSize; /* not enough memory */
+
+ /* loop on each file */
+ for (i=0; i<ifntSize; i++) {
+ size_t const ifnSize = strlen(inFileNamesTable[i]);
+ if (!strcmp(suffix, stdoutmark)) {
+ missed_files += LZ4IO_compressFilename_Legacy(prefs,
+ inFileNamesTable[i], stdoutmark,
+ compressionLevel);
+ continue;
+ }
+
+ if (ofnSize <= ifnSize+suffixSize+1) {
+ free(dstFileName);
+ ofnSize = ifnSize + 20;
+ dstFileName = (char*)malloc(ofnSize);
+ if (dstFileName==NULL) {
+ return ifntSize;
+ } }
+ strcpy(dstFileName, inFileNamesTable[i]);
+ strcat(dstFileName, suffix);
+
+ missed_files += LZ4IO_compressFilename_Legacy(prefs,
+ inFileNamesTable[i], dstFileName,
+ compressionLevel);
+ }
+
+ /* Close & Free */
+ free(dstFileName);
+
+ return missed_files;
+}
+
/*********************************************
* Compression using Frame format
@@ -749,7 +797,6 @@ int LZ4IO_compressFilename(LZ4IO_prefs_t* const prefs, const char* srcFileName,
}
-#define FNSPACE 30
int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs,
const char** inFileNamesTable, int ifntSize,
const char* suffix,