MCPcopy Create free account
hub / github.com/F-Stack/f-stack / FIO_checkFilenameCollisions

Function FIO_checkFilenameCollisions

freebsd/contrib/zstd/programs/fileio.c:734–764  ·  view source on GitHub ↗

FIO_checkFilenameCollisions() : * Checks for and warns if there are any files that would have the same output path */

Source from the content-addressed store, hash-verified

732 * Checks for and warns if there are any files that would have the same output path
733 */
734int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles) {
735 const char **filenameTableSorted, *prevElem, *filename;
736 unsigned u;
737
738 filenameTableSorted = (const char**) malloc(sizeof(char*) * nbFiles);
739 if (!filenameTableSorted) {
740 DISPLAY("Unable to malloc new str array, not checking for name collisions\n");
741 return 1;
742 }
743
744 for (u = 0; u < nbFiles; ++u) {
745 filename = strrchr(filenameTable[u], PATH_SEP);
746 if (filename == NULL) {
747 filenameTableSorted[u] = filenameTable[u];
748 } else {
749 filenameTableSorted[u] = filename+1;
750 }
751 }
752
753 qsort((void*)filenameTableSorted, nbFiles, sizeof(char*), UTIL_compareStr);
754 prevElem = filenameTableSorted[0];
755 for (u = 1; u < nbFiles; ++u) {
756 if (strcmp(prevElem, filenameTableSorted[u]) == 0) {
757 DISPLAY("WARNING: Two files have same filename: %s\n", prevElem);
758 }
759 prevElem = filenameTableSorted[u];
760 }
761
762 free((void*)filenameTableSorted);
763 return 0;
764}
765
766static const char*
767extractFilename(const char* path, char separator)

Callers 2

Calls 5

mallocFunction · 0.85
strrchrFunction · 0.85
qsortFunction · 0.85
strcmpFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected