diff options
author | Yann Collet <yann.collet.73@gmail.com> | 2015-04-13 19:03:51 (GMT) |
---|---|---|
committer | Yann Collet <yann.collet.73@gmail.com> | 2015-04-13 19:03:51 (GMT) |
commit | ccba7a0a29f00728e5fa87855d9e56ec86d3c5be (patch) | |
tree | 2b47e0a8ddac4d2866b7462c78adb8a4f427c675 /programs/lz4io.c | |
parent | bc28fc1a0df8de9e9ec847430dae5873dac7a4d5 (diff) | |
parent | 7f2f1fcd5541976e79026ba00465f54b41ae29c2 (diff) | |
download | lz4-ccba7a0a29f00728e5fa87855d9e56ec86d3c5be.zip lz4-ccba7a0a29f00728e5fa87855d9e56ec86d3c5be.tar.gz lz4-ccba7a0a29f00728e5fa87855d9e56ec86d3c5be.tar.bz2 |
Merge pull request #86 from KyleJHarper/origin/r129/multiple_inputs_patch
Origin/r129/multiple inputs patch
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r-- | programs/lz4io.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c index 1595a0d..c510f1d 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -508,12 +508,21 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel) { int i; + int missing_files = 0; + FILE *ifp; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); for (i=0; i<ifntSize; i++) { + ifp = fopen(inFileNamesTable[i], "r"); + if (ifp == NULL) { + DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", inFileNamesTable[i]); + missing_files++; + continue; + } + fclose(ifp); size_t ifnSize = strlen(inFileNamesTable[i]); if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); } strcpy(outFileName, inFileNamesTable[i]); @@ -521,9 +530,47 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel); } free(outFileName); + if (missing_files > 0) return 1; return 0; } +int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) +{ + int i; + int skipped_files = 0; + int missing_files = 0; + FILE *ifp; + char* outFileName = (char*)malloc(FNSPACE); + size_t ofnSize = FNSPACE; + size_t suffixSize = strlen(suffix); + char* ifnSuffix = (char*)malloc(suffixSize + 1); + + for (i=0; i<ifntSize; i++) + { + ifp = fopen(inFileNamesTable[i], "r"); + if (ifp == NULL) { + DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", inFileNamesTable[i]); + missing_files++; + continue; + } + fclose(ifp); + size_t ifnSize = strlen(inFileNamesTable[i]); + strcpy(ifnSuffix, inFileNamesTable[i] + ifnSize - suffixSize); + if (ofnSize <= ifnSize-suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); } + if (ifnSize <= suffixSize || strcmp(ifnSuffix, suffix) != 0) { + DISPLAYLEVEL(2, "File extension doesn't match expected LZ4_EXTENSION (%4s); will not process file: %s\n", suffix, inFileNamesTable[i]); + skipped_files++; + continue; + } + memcpy(outFileName, inFileNamesTable[i], ifnSize - suffixSize); + outFileName[ifnSize-suffixSize] = '\0'; + LZ4IO_decompressFilename(inFileNamesTable[i], outFileName); + } + free(outFileName); + if (skipped_files > 0) return 1; + if (missing_files > 0) return 1; + return 0; +} /* ********************************************************************* */ /* ********************** LZ4 file-stream Decompression **************** */ |