1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

better naming

and more narrow scope of local variables
This commit is contained in:
Yann Collet
2025-03-24 21:20:21 -07:00
parent 7630870b47
commit 76c2fdc7b7
4 changed files with 21 additions and 20 deletions

View File

@ -723,34 +723,33 @@ UTIL_createLinePointers(char* buffer, size_t numLines, size_t bufferSize)
} }
FileNamesTable* FileNamesTable*
UTIL_createFileNamesTable_fromFileName(const char* inputFileName) UTIL_createFileNamesTable_fromFileList(const char* fileList)
{ {
stat_t statbuf; stat_t statbuf;
FILE* inFile = NULL;
char* buffer = NULL; char* buffer = NULL;
const char** linePointers = NULL;
size_t numLines = 0; size_t numLines = 0;
size_t bufferSize = 0; size_t bufferSize = 0;
/* Check if the input is a valid file */ /* Check if the input is a valid file */
if (!UTIL_stat(inputFileName, &statbuf)) { if (!UTIL_stat(fileList, &statbuf)) {
return NULL; return NULL;
} }
/* Check if the input is a supported type */ /* Check if the input is a supported type */
if (!UTIL_isRegularFileStat(&statbuf) && if (!UTIL_isRegularFileStat(&statbuf) &&
!UTIL_isFIFOStat(&statbuf) && !UTIL_isFIFOStat(&statbuf) &&
!UTIL_isFileDescriptorPipe(inputFileName)) { !UTIL_isFileDescriptorPipe(fileList)) {
return NULL; return NULL;
} }
/* Open the input file */ /* Open the input file */
inFile = fopen(inputFileName, "rb"); { FILE* const inFile = fopen(fileList, "rb");
if (inFile == NULL) return NULL; if (inFile == NULL) return NULL;
/* Read the file content */ /* Read the file content */
buffer = UTIL_readFileContent(inFile, &bufferSize); buffer = UTIL_readFileContent(inFile, &bufferSize);
fclose(inFile); fclose(inFile);
}
if (buffer == NULL) return NULL; if (buffer == NULL) return NULL;
@ -762,14 +761,15 @@ UTIL_createFileNamesTable_fromFileName(const char* inputFileName)
} }
/* Create line pointers */ /* Create line pointers */
linePointers = UTIL_createLinePointers(buffer, numLines, bufferSize); { const char** linePointers = UTIL_createLinePointers(buffer, numLines, bufferSize);
if (linePointers == NULL) { if (linePointers == NULL) {
free(buffer); free(buffer);
return NULL; return NULL;
} }
/* Create the final table */ /* Create the final table */
return UTIL_assembleFileNamesTable(linePointers, numLines, buffer); return UTIL_assembleFileNamesTable(linePointers, numLines, buffer);
}
} }

View File

@ -251,13 +251,13 @@ typedef struct
size_t tableCapacity; size_t tableCapacity;
} FileNamesTable; } FileNamesTable;
/*! UTIL_createFileNamesTable_fromFileName() : /*! UTIL_createFileNamesTable_fromFileList() :
* read filenames from @inputFileName, and store them into returned object. * read filenames from @inputFileName, and store them into returned object.
* @return : a FileNamesTable*, or NULL in case of error (ex: @inputFileName doesn't exist). * @return : a FileNamesTable*, or NULL in case of error (ex: @inputFileName doesn't exist).
* Note: inputFileSize must be less than 50MB * Note: inputFileSize must be less than 50MB
*/ */
FileNamesTable* FileNamesTable*
UTIL_createFileNamesTable_fromFileName(const char* inputFileName); UTIL_createFileNamesTable_fromFileList(const char* inputFileName);
/*! UTIL_assembleFileNamesTable() : /*! UTIL_assembleFileNamesTable() :
* This function takes ownership of its arguments, @filenames and @buf, * This function takes ownership of its arguments, @filenames and @buf,

View File

@ -1379,7 +1379,7 @@ int main(int argCount, const char* argv[])
size_t const nbFileLists = file_of_names->tableSize; size_t const nbFileLists = file_of_names->tableSize;
size_t flNb; size_t flNb;
for (flNb=0; flNb < nbFileLists; 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) { if (fnt==NULL) {
DISPLAYLEVEL(1, "zstd: error reading %s \n", file_of_names->fileNames[flNb]); DISPLAYLEVEL(1, "zstd: error reading %s \n", file_of_names->fileNames[flNb]);
CLEAN_RETURN(1); CLEAN_RETURN(1);

View File

@ -848,6 +848,7 @@ ls tmp* > tmpList
zstd -f tmp1 --filelist=tmpList --filelist=tmpList tmp2 tmp3 # can trigger an overflow of internal file list zstd -f tmp1 --filelist=tmpList --filelist=tmpList tmp2 tmp3 # can trigger an overflow of internal file list
rm -rf tmp* rm -rf tmp*
println "\n===> --[no-]content-size tests" println "\n===> --[no-]content-size tests"
datagen > tmp_contentsize datagen > tmp_contentsize