diff options
author | Kyle J Harper <KyleJHarper@gmail.com> | 2015-04-12 23:41:55 (GMT) |
---|---|---|
committer | Kyle J Harper <KyleJHarper@gmail.com> | 2015-04-12 23:41:55 (GMT) |
commit | 7f2f1fcd5541976e79026ba00465f54b41ae29c2 (patch) | |
tree | 573085747ba439db95faa5ecfabd6f82f25b70e8 /programs/lz4io.c | |
parent | 0169502b49dfa5eb8878f5c85be3270012266fc3 (diff) | |
download | lz4-7f2f1fcd5541976e79026ba00465f54b41ae29c2.zip lz4-7f2f1fcd5541976e79026ba00465f54b41ae29c2.tar.gz lz4-7f2f1fcd5541976e79026ba00465f54b41ae29c2.tar.bz2 |
Added support for continuation of file compression and decompression if input files are missing. Should more closely match gzip/bzip2/xz and so forth. Also removed a debug print accidentally left in.
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r-- | programs/lz4io.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c index 16a588c..d399c90 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -501,12 +501,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]); @@ -514,6 +523,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel); } free(outFileName); + if (missing_files > 0) return 1; return 0; } @@ -521,6 +531,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz { 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); @@ -528,13 +540,19 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz 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); - DISPLAYLEVEL(2, "ifnSuffix is %s\n", ifnSuffix); 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 = 1; + skipped_files++; continue; } memcpy(outFileName, inFileNamesTable[i], ifnSize - suffixSize); @@ -542,7 +560,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz LZ4IO_decompressFilename(inFileNamesTable[i], outFileName); } free(outFileName); - if (skipped_files) return 1; + if (skipped_files > 0) return 1; + if (missing_files > 0) return 1; return 0; } |