FR #598 - Move LZ4F_compFileInfo_t def to lz4frame.h discard output_file

assert if in om_list mode
This commit is contained in:
gabrielstedman 2019-04-22 09:58:26 +01:00
parent 9d0960c354
commit 0acebbe53d
4 changed files with 24 additions and 15 deletions

View File

@ -193,6 +193,13 @@ typedef struct {
#define LZ4F_INIT_PREFERENCES { LZ4F_INIT_FRAMEINFO, 0, 0u, 0u, { 0u, 0u, 0u } } /* v1.8.3+ */
typedef struct {
LZ4F_frameInfo_t frameInfo;
const char* fileName;
unsigned long fileSize;
} LZ4F_compFileInfo_t;
#define LZ4F_INIT_FILEINFO { (LZ4F_frameInfo_t) LZ4F_INIT_FRAMEINFO, NULL, 0UL }
/*-*********************************
* Simple compression function

View File

@ -693,7 +693,7 @@ int main(int argc, const char** argv)
break;
}
if (multiple_inputs==0) assert(output_filename);
if (multiple_inputs==0 && mode != om_list) assert(output_filename);
/* when multiple_inputs==1, output_filename may simply be useless,
* however, output_filename must be !NULL for next strcmp() tests */
if (!output_filename) output_filename = "*\\dummy^!//";
@ -721,7 +721,14 @@ int main(int argc, const char** argv)
operationResult = LZ4IO_decompressMultipleFilenames(prefs, inFileNames, (int)ifnIdx, !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION);
} else {
operationResult = DEFAULT_DECOMPRESSOR(prefs, input_filename, output_filename);
}
} else if (mode == om_list){
if(!multiple_inputs){
inFileNames[ifnIdx++] = input_filename;
}
operationResult = LZ4IO_displayCompressedFilesInfo(inFileNames, ifnIdx);
inFileNames=NULL;
} else { /* compression is default action */
if (legacy_format) {
DISPLAYLEVEL(3, "! Generating LZ4 Legacy format (deprecated) ! \n");
LZ4IO_compressFilename_Legacy(prefs, input_filename, output_filename, cLevel);
@ -745,4 +752,4 @@ _cleanup:
LZ4IO_freePreferences(prefs);
free((void*)inFileNames);
return operationResult;
}
}

View File

@ -1218,6 +1218,7 @@ static int LZ4IO_getCompressedFileInfo(const char* input_filename, LZ4F_compFil
const char *b,
*e;
char *t;
stat_t statbuf;
size_t readSize = LZ4F_HEADER_SIZE_MAX;
LZ4F_errorCode_t errorCode;
dRess_t ress;
@ -1227,10 +1228,12 @@ static int LZ4IO_getCompressedFileInfo(const char* input_filename, LZ4F_compFil
if (finput==NULL) return 1;
/* Get file size */
if (!UTIL_getFileStat(input_filename, &cfinfo->fileStat)){
if (!UTIL_getFileStat(input_filename, &statbuf)){
EXM_THROW(60, "Can't stat file : %s", input_filename);
}
cfinfo->fileSize = statbuf.st_size;
/* Get basename without extension */
b = strrchr(input_filename, '/');
if (!b){
@ -1336,11 +1339,11 @@ int LZ4IO_displayCompressedFilesInfo(const char** inFileNames, const size_t ifnI
break;
}
if(cfinfo.frameInfo.contentSize){
ratio = (double)cfinfo.fileStat.st_size / cfinfo.frameInfo.contentSize;
DISPLAY("%-16d\t%-20lu\t%-20llu\t%-8.4f\t%s\n",cfinfo.frameInfo.blockChecksumFlag,cfinfo.fileStat.st_size,cfinfo.frameInfo.contentSize, ratio, cfinfo.fileName);
ratio = (double)cfinfo.fileSize / cfinfo.frameInfo.contentSize;
DISPLAY("%-16d\t%-20lu\t%-20llu\t%-8.4f\t%s\n",cfinfo.frameInfo.blockChecksumFlag,cfinfo.fileSize,cfinfo.frameInfo.contentSize, ratio, cfinfo.fileName);
}
else{
DISPLAY("%-16d\t%-20lu\t%-20s\t%-10s\t%s\n",cfinfo.frameInfo.blockChecksumFlag,cfinfo.fileStat.st_size, "-", "-", cfinfo.fileName);
DISPLAY("%-16d\t%-20lu\t%-20s\t%-10s\t%s\n",cfinfo.frameInfo.blockChecksumFlag,cfinfo.fileSize, "-", "-", cfinfo.fileName);
}
}
return op_result;

View File

@ -52,14 +52,6 @@ static const char nulmark[] = "/dev/null";
/* ****************** Type Definitions ************** */
/* ************************************************** */
typedef struct {
LZ4F_frameInfo_t frameInfo;
const char* fileName;
stat_t fileStat;
} LZ4F_compFileInfo_t;
#define LZ4F_INIT_FILEINFO { (LZ4F_frameInfo_t) LZ4F_INIT_FRAMEINFO, NULL, stat_t() }
typedef struct LZ4IO_prefs_s LZ4IO_prefs_t;
LZ4IO_prefs_t* LZ4IO_defaultPreferences(void);