summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2019-04-22 19:27:25 (GMT)
committerYann Collet <cyan@fb.com>2019-04-22 19:27:25 (GMT)
commitae5cea9112479df58d226f79ae34c07bc636a04d (patch)
tree62e2f07c0a6210176e0fab4acdaf6af913fb8a9d
parent4ae437c98e8674b7e425e1bf61b9f8e0ff1989bd (diff)
downloadlz4-ae5cea9112479df58d226f79ae34c07bc636a04d.zip
lz4-ae5cea9112479df58d226f79ae34c07bc636a04d.tar.gz
lz4-ae5cea9112479df58d226f79ae34c07bc636a04d.tar.bz2
fixed C90 compliance
re-structure code, have everything into a single section of lz4io.c
-rw-r--r--lib/lz4frame.h7
-rw-r--r--programs/lz4cli.c2
-rw-r--r--programs/lz4io.c127
-rw-r--r--programs/lz4io.h6
4 files changed, 74 insertions, 68 deletions
diff --git a/lib/lz4frame.h b/lib/lz4frame.h
index 8c07e86..742c252 100644
--- a/lib/lz4frame.h
+++ b/lib/lz4frame.h
@@ -193,13 +193,6 @@ 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 long fileSize;
-} LZ4F_compFileInfo_t;
-
-#define LZ4F_INIT_FILEINFO { (LZ4F_frameInfo_t) LZ4F_INIT_FRAMEINFO, NULL, 0ULL }
/*-*********************************
* Simple compression function
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 443e4b4..39ff1ea 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -752,4 +752,4 @@ _cleanup:
LZ4IO_freePreferences(prefs);
free((void*)inFileNames);
return operationResult;
-} \ No newline at end of file
+}
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 175157e..1e6efe1 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -1214,62 +1214,6 @@ static int LZ4IO_decompressDstFile(LZ4IO_prefs_t* const prefs, dRess_t ress, con
}
-static int LZ4IO_getCompressedFileInfo(const char* input_filename, LZ4F_compFileInfo_t* cfinfo){
- const char *b,
- *e;
- char *t;
- stat_t statbuf;
- size_t readSize = LZ4F_HEADER_SIZE_MAX;
- LZ4F_errorCode_t errorCode;
- dRess_t ress;
- /* Open file */
- FILE* const finput = LZ4IO_openSrcFile(input_filename);
- if (finput==NULL) return 1;
-
- /* Get file size */
- 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){
- b = strrchr(input_filename, '\\');
- }
- if (b && b != input_filename){
- b++;
- } else{
- b=input_filename;
- }
- e = strrchr(b, '.');
-
- /* Allocate Memory */
- t = (char*)malloc( (e-b+1) * sizeof(char));
- ress.srcBuffer = malloc(LZ4IO_dBufferSize);
- if (!t || !ress.srcBuffer)
- EXM_THROW(21, "Allocation error : not enough memory");
- strncpy(t, b, (e-b));
- t[e-b] = '\0';
- cfinfo->fileName = t;
-
- /* init */
- errorCode = LZ4F_createDecompressionContext(&ress.dCtx, LZ4F_VERSION);
- if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create LZ4F context : %s", LZ4F_getErrorName(errorCode));
-
- if (!fread(ress.srcBuffer, readSize, 1, finput)){
- EXM_THROW(30, "Error reading %s ", input_filename);
- }
- LZ4F_getFrameInfo(ress.dCtx, &cfinfo->frameInfo, ress.srcBuffer, &readSize);
-
- /* Close input/free resources */
- fclose(finput);
- free(ress.srcBuffer);
- return 0;
-}
-
-
int LZ4IO_decompressFilename(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename)
{
dRess_t const ress = LZ4IO_createDResources(prefs);
@@ -1323,15 +1267,82 @@ int LZ4IO_decompressMultipleFilenames(LZ4IO_prefs_t* const prefs, const char** i
}
+/* ********************************************************************* */
+/* ********************** LZ4 --list command *********************** */
+/* ********************************************************************* */
+
+typedef struct {
+ LZ4F_frameInfo_t frameInfo;
+ const char* fileName;
+ unsigned long long fileSize;
+} LZ4F_compFileInfo_t;
+
+#define LZ4F_INIT_FILEINFO { LZ4F_INIT_FRAMEINFO, NULL, 0ULL }
+
+
+static int LZ4IO_getCompressedFileInfo(const char* input_filename, LZ4F_compFileInfo_t* cfinfo){
+ const char *b,
+ *e;
+ char *t;
+ stat_t statbuf;
+ size_t readSize = LZ4F_HEADER_SIZE_MAX;
+ LZ4F_errorCode_t errorCode;
+ dRess_t ress;
+ /* Open file */
+ FILE* const finput = LZ4IO_openSrcFile(input_filename);
+ if (finput==NULL) return 1;
+
+ /* Get file size */
+ if (!UTIL_getFileStat(input_filename, &statbuf)){
+ EXM_THROW(60, "Can't stat file : %s", input_filename);
+ }
+
+ cfinfo->fileSize = (unsigned long long)statbuf.st_size;
+
+ /* Get basename without extension */
+ b = strrchr(input_filename, '/');
+ if (!b){
+ b = strrchr(input_filename, '\\');
+ }
+ if (b && b != input_filename){
+ b++;
+ } else{
+ b=input_filename;
+ }
+ e = strrchr(b, '.');
+
+ /* Allocate Memory */
+ t = (char*)malloc( (size_t)(e-b+1) * sizeof(char));
+ ress.srcBuffer = malloc(LZ4IO_dBufferSize);
+ if (!t || !ress.srcBuffer)
+ EXM_THROW(21, "Allocation error : not enough memory");
+ strncpy(t, b, (e-b));
+ t[e-b] = '\0';
+ cfinfo->fileName = t;
+
+ /* init */
+ errorCode = LZ4F_createDecompressionContext(&ress.dCtx, LZ4F_VERSION);
+ if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create LZ4F context : %s", LZ4F_getErrorName(errorCode));
+
+ if (!fread(ress.srcBuffer, readSize, 1, finput)){
+ EXM_THROW(30, "Error reading %s ", input_filename);
+ }
+ LZ4F_getFrameInfo(ress.dCtx, &cfinfo->frameInfo, ress.srcBuffer, &readSize);
+
+ /* Close input/free resources */
+ fclose(finput);
+ free(ress.srcBuffer);
+ return 0;
+}
+
int LZ4IO_displayCompressedFilesInfo(const char** inFileNames, const size_t ifnIdx){
size_t idx;
int op_result=0;
double ratio;
- LZ4F_compFileInfo_t cfinfo;
DISPLAY("%16s\t%-20s\t%-20s\t%-10s\t%s\n","BlockChecksumFlag","Compressed", "Uncompressed", "Ratio", "Filename");
for(idx=0; idx<ifnIdx; idx++){
/* Get file info */
- cfinfo = (LZ4F_compFileInfo_t) LZ4F_INIT_FILEINFO;
+ LZ4F_compFileInfo_t cfinfo = LZ4F_INIT_FILEINFO;
op_result=LZ4IO_getCompressedFileInfo(inFileNames[idx], &cfinfo);
if (op_result != 0){
DISPLAYLEVEL(1, "Failed to get frame info for file %s\n", inFileNames[idx]);
diff --git a/programs/lz4io.h b/programs/lz4io.h
index 2008b55..7dba954 100644
--- a/programs/lz4io.h
+++ b/programs/lz4io.h
@@ -116,8 +116,6 @@ int LZ4IO_setSparseFile(LZ4IO_prefs_t* const prefs, int enable);
/* Default setting : 0 == no content size present in frame header */
int LZ4IO_setContentSize(LZ4IO_prefs_t* const prefs, int enable);
-int LZ4IO_displayCompressedFilesInfo(const char** inFileNames,const size_t ifnIdx);
-
/* Default setting : 0 == src file preserved */
void LZ4IO_setRemoveSrcFile(LZ4IO_prefs_t* const prefs, unsigned flag);
@@ -126,4 +124,8 @@ void LZ4IO_setRemoveSrcFile(LZ4IO_prefs_t* const prefs, unsigned flag);
void LZ4IO_favorDecSpeed(LZ4IO_prefs_t* const prefs, int favor);
+/* implement --list */
+int LZ4IO_displayCompressedFilesInfo(const char** inFileNames,const size_t ifnIdx);
+
+
#endif /* LZ4IO_H_237902873 */