diff options
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; } |