1
0
mirror of https://github.com/facebook/zstd.git synced 2025-08-01 09:47:01 +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*
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);
}
}

View 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,

View 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);

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
rm -rf tmp*
println "\n===> --[no-]content-size tests"
datagen > tmp_contentsize