FIO_checkFilenameCollisions() : * Checks for and warns if there are any files that would have the same output path */
| 732 | * Checks for and warns if there are any files that would have the same output path |
| 733 | */ |
| 734 | int 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 | |
| 766 | static const char* |
| 767 | extractFilename(const char* path, char separator) |