changed name from createX to assembleX

shows that the resulting object just takes ownership of provided buffer.
This commit is contained in:
Yann Collet 2019-11-25 15:34:55 -08:00
parent 9df49dc50a
commit 9a3de0a535
3 changed files with 10 additions and 10 deletions

View File

@ -770,7 +770,7 @@ int main (int argc, const char** argv)
if (argc < 2) return bad_usage(exeName);
const char** nameTable = (const char**)malloc(argc * sizeof(const char*));
const char** nameTable = (const char**)malloc((size_t)argc * sizeof(const char*));
assert(nameTable != NULL);
unsigned nameIdx = 0;
@ -805,7 +805,7 @@ int main (int argc, const char** argv)
#endif
filenameTable = UTIL_createExpandedFNT(nameTable, nameIdx, 1 /* follow_links */);
} else {
filenameTable = UTIL_createFileNamesTable(nameTable, nameIdx, NULL);
filenameTable = UTIL_assembleFileNamesTable(nameTable, nameIdx, NULL);
nameTable = NULL; /* UTIL_createFileNamesTable() takes ownership of nameTable */
}

View File

@ -323,12 +323,12 @@ UTIL_createFileNamesTable_fromFileName(const char* inputFileName)
} }
assert(pos <= bufSize);
return UTIL_createFileNamesTable(filenamesTable, nbFiles, buf);
return UTIL_assembleFileNamesTable(filenamesTable, nbFiles, buf);
}
}
FileNamesTable*
UTIL_createFileNamesTable(const char** filenames, size_t tableSize, char* buf)
UTIL_assembleFileNamesTable(const char** filenames, size_t tableSize, char* buf)
{
FileNamesTable* const table = (FileNamesTable*) malloc(sizeof(*table));
if(!table) return NULL;
@ -352,7 +352,7 @@ FileNamesTable* UTIL_allocateFileNamesTable(size_t tableSize)
const char** const fnTable = (const char**)malloc(tableSize * sizeof(*fnTable));
FileNamesTable* fnt;
if (fnTable==NULL) return NULL;
fnt = UTIL_createFileNamesTable(fnTable, tableSize, NULL);
fnt = UTIL_assembleFileNamesTable(fnTable, tableSize, NULL);
fnt->tableSize = 0; /* the table is empty */
return fnt;
}
@ -381,7 +381,7 @@ UTIL_mergeFileNamesTable(FileNamesTable* table1, FileNamesTable* table2)
size_t newTotalTableSize;
char* buf;
FileNamesTable* const newTable = UTIL_createFileNamesTable(NULL, 0, NULL);
FileNamesTable* const newTable = UTIL_assembleFileNamesTable(NULL, 0, NULL);
CONTROL( newTable != NULL );
newTotalTableSize = getTotalTableSize(table1) + getTotalTableSize(table2);
@ -630,7 +630,7 @@ UTIL_createExpandedFNT(const char** inputNames, size_t nbIfns, int followLinks)
pos += strlen(fileNamesTable[ifnNb]) + 1;
}
return UTIL_createFileNamesTable(fileNamesTable, nbFiles, buf);
return UTIL_assembleFileNamesTable(fileNamesTable, nbFiles, buf);
}
}
@ -648,7 +648,7 @@ FileNamesTable* UTIL_createFNT_fromROTable(const char** filenames, size_t nbFile
const char** const newFNTable = (const char**)malloc(sizeof_FNTable);
if (newFNTable==NULL) return NULL;
memcpy((void*)newFNTable, filenames, sizeof_FNTable); /* void* : mitigate a Visual compiler bug or limitation */
return UTIL_createFileNamesTable(newFNTable, nbFilenames, NULL);
return UTIL_assembleFileNamesTable(newFNTable, nbFilenames, NULL);
}

View File

@ -175,13 +175,13 @@ typedef struct
FileNamesTable*
UTIL_createFileNamesTable_fromFileName(const char* inputFileName);
/*! UTIL_createFileNamesTable() :
/*! UTIL_assembleFileNamesTable() :
* This function takes ownership of its arguments, @filenames and @buf,
* and store them inside the created object.
* @return : FileNamesTable*, or NULL, if allocation fails.
*/
FileNamesTable*
UTIL_createFileNamesTable(const char** filenames, size_t tableSize, char* buf);
UTIL_assembleFileNamesTable(const char** filenames, size_t tableSize, char* buf);
/*! UTIL_freeFileNamesTable() :
* This function is compatible with NULL argument and never fails.