]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
better naming
authorYann Collet <cyan@fb.com>
Tue, 25 Mar 2025 04:20:21 +0000 (21:20 -0700)
committerYann Collet <cyan@fb.com>
Fri, 28 Mar 2025 16:18:17 +0000 (09:18 -0700)
and more narrow scope of local variables

programs/util.c
programs/util.h
programs/zstdcli.c
tests/playTests.sh

index b6431b49fbff3855787120d582f6d0241569a289..43f2b9408c7eaa0061015c6fa3ed708f74d7fd91 100644 (file)
@@ -723,34 +723,33 @@ UTIL_createLinePointers(char* buffer, size_t numLines, size_t bufferSize)
 }
 
 FileNamesTable*
-UTIL_createFileNamesTable_fromFileName(const char* inputFileName)
+UTIL_createFileNamesTable_fromFileList(const char* fileList)
 {
     stat_t statbuf;
-    FILE* inFile = NULL;
     char* buffer = NULL;
-    const char** linePointers = NULL;
     size_t numLines = 0;
     size_t bufferSize = 0;
 
     /* Check if the input is a valid file */
-    if (!UTIL_stat(inputFileName, &statbuf)) {
+    if (!UTIL_stat(fileList, &statbuf)) {
         return NULL;
     }
 
     /* Check if the input is a supported type */
     if (!UTIL_isRegularFileStat(&statbuf) &&
         !UTIL_isFIFOStat(&statbuf) &&
-        !UTIL_isFileDescriptorPipe(inputFileName)) {
+        !UTIL_isFileDescriptorPipe(fileList)) {
         return NULL;
     }
 
     /* Open the input file */
-    inFile = fopen(inputFileName, "rb");
-    if (inFile == NULL) return NULL;
+    {   FILE* const inFile = fopen(fileList, "rb");
+        if (inFile == NULL) return NULL;
 
-    /* Read the file content */
-    buffer = UTIL_readFileContent(inFile, &bufferSize);
-    fclose(inFile);
+        /* Read the file content */
+        buffer = UTIL_readFileContent(inFile, &bufferSize);
+        fclose(inFile);
+    }
 
     if (buffer == NULL) return NULL;
 
@@ -762,14 +761,15 @@ UTIL_createFileNamesTable_fromFileName(const char* inputFileName)
     }
 
     /* Create line pointers */
-    linePointers = UTIL_createLinePointers(buffer, numLines, bufferSize);
-    if (linePointers == NULL) {
-        free(buffer);
-        return NULL;
-    }
+    {   const char** linePointers = UTIL_createLinePointers(buffer, numLines, bufferSize);
+        if (linePointers == NULL) {
+            free(buffer);
+            return NULL;
+        }
 
-    /* Create the final table */
-    return UTIL_assembleFileNamesTable(linePointers, numLines, buffer);
+        /* Create the final table */
+        return UTIL_assembleFileNamesTable(linePointers, numLines, buffer);
+    }
 }
 
 
index 5fd5de40b2632e6507ba569355ff64c0fca3b691..427bcf441ea6163a2b773f349e4f78a641bd2d10 100644 (file)
@@ -251,13 +251,13 @@ typedef struct
     size_t tableCapacity;
 } FileNamesTable;
 
-/*! UTIL_createFileNamesTable_fromFileName() :
+/*! UTIL_createFileNamesTable_fromFileList() :
  *  read filenames from @inputFileName, and store them into returned object.
  * @return : a FileNamesTable*, or NULL in case of error (ex: @inputFileName doesn't exist).
  *  Note: inputFileSize must be less than 50MB
  */
 FileNamesTable*
-UTIL_createFileNamesTable_fromFileName(const char* inputFileName);
+UTIL_createFileNamesTable_fromFileList(const char* inputFileName);
 
 /*! UTIL_assembleFileNamesTable() :
  *  This function takes ownership of its arguments, @filenames and @buf,
index b9f961c165418b6cf3525cb4348d54b82a1506bf..fa7ea37b3f0f252a76cced51a62fb70f77fd7e76 100644 (file)
@@ -1379,7 +1379,7 @@ int main(int argCount, const char* argv[])
         size_t const nbFileLists = file_of_names->tableSize;
         size_t flNb;
         for (flNb=0; flNb < nbFileLists; flNb++) {
-            FileNamesTable* const fnt = UTIL_createFileNamesTable_fromFileName(file_of_names->fileNames[flNb]);
+            FileNamesTable* const fnt = UTIL_createFileNamesTable_fromFileList(file_of_names->fileNames[flNb]);
             if (fnt==NULL) {
                 DISPLAYLEVEL(1, "zstd: error reading %s \n", file_of_names->fileNames[flNb]);
                 CLEAN_RETURN(1);
index 486b395eb53d18d02ee3aa83510459104aaa2c1b..d3ce39846ce2053fdb91d08aa5865873565c07af 100755 (executable)
@@ -848,6 +848,7 @@ ls tmp* > tmpList
 zstd -f tmp1 --filelist=tmpList --filelist=tmpList tmp2 tmp3  # can trigger an overflow of internal file list
 rm -rf tmp*
 
+
 println "\n===> --[no-]content-size tests"
 
 datagen > tmp_contentsize