UTIL_assembleFileNamesTable(const char** filenames, size_t tableSize, char* buf)
{
FileNamesTable* const table = (FileNamesTable*) malloc(sizeof(*table));
- if(!table) return NULL;
+ CONTROL(table != NULL);
table->fileNames = filenames;
table->buf = buf;
table->tableSize = tableSize;
}
if (errno != 0) {
- UTIL_DISPLAYLEVEL(1, "readdir(%s) error: %s\n", dirName, strerror(errno));
+ UTIL_DISPLAYLEVEL(1, "readdir(%s) error: %s \n", dirName, strerror(errno));
free(*bufStart);
*bufStart = NULL;
}
char** bufEnd, int followLinks)
{
(void)bufStart; (void)bufEnd; (void)pos; (void)followLinks;
- UTIL_DISPLAYLEVEL(1, "Directory %s ignored (compiled without _WIN32 or _POSIX_C_SOURCE)\n", dirName);
+ UTIL_DISPLAYLEVEL(1, "Directory %s ignored (compiled without _WIN32 or _POSIX_C_SOURCE) \n", dirName);
return 0;
}
pos += strlen(fileNamesTable[ifnNb]) + 1;
}
{ FileNamesTable* const fnt = UTIL_assembleFileNamesTable(fileNamesTable, nbFiles, buf);
-#ifdef __clang_analyzer__
+#if 0 && defined(__clang_analyzer__)
+ /* note : this trick might not be necessary anymore */
/* scan-build does not understand ownership transfer.
* In _some_ versions, it believes that there is a leak of @buf and @fileNamesTable
* on leaving the function, which is not the case,
}
} else {
done = TRUE;
- }
- }
+ } }
ptr = buffer;
} else if (ferror(cpuinfo)) {
/* fall back on the sysconf value */
goto failed;
- }
- }
+ } }
if (siblings && cpu_cores) {
ratio = siblings / cpu_cores;
}
#include <sys/stat.h> /* stat, chmod */
#include "mem.h" /* U64 */
+
/*-************************************************************
* Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW
***************************************************************/
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
-# define UTIL_fseek _fseeki64
+# define UTIL_fseek _fseeki64
#elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */
# define UTIL_fseek fseeko
#elif defined(__MINGW32__) && defined(__MSVCRT__) && !defined(__STRICT_ANSI__) && !defined(__NO_MINGW_LFS)
-# define UTIL_fseek fseeko64
+# define UTIL_fseek fseeko64
#else
-# define UTIL_fseek fseek
+# define UTIL_fseek fseek
#endif
* Lists of Filenames
******************************************/
-#ifdef _WIN32
-# define UTIL_HAS_CREATEFILELIST
-#elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */
-# define UTIL_HAS_CREATEFILELIST
-#else
- /* do not define UTIL_HAS_CREATEFILELIST */
-#endif /* #ifdef _WIN32 */
-
typedef struct
-{
- const char** fileNames;
+{ const char** fileNames;
char* buf; /* fileNames are stored in this buffer (or are read-only) */
size_t tableSize; /* nb of fileNames */
size_t tableCapacity;
/*! 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.
+ * note : this function never fails,
+ * it will rather exit() the program if internal allocation fails.
+ * @return : resulting FileNamesTable* object.
*/
FileNamesTable*
UTIL_assembleFileNamesTable(const char** filenames, size_t tableSize, char* buf);
* @return : a FileNamesTable* object,
* or NULL in case of error
*/
-FileNamesTable* UTIL_createFNT_fromROTable(const char** filenames, size_t nbFilenames);
-
-/*! UTIL_createExpandedFNT() :
- * read names from @filenames, and expand those corresponding to directories
- * @return : an expanded FileNamesTable*, where each name is a file
- * or NULL in case of error
- */
-FileNamesTable* UTIL_createExpandedFNT(const char** filenames, size_t nbFilenames, int followLinks);
-
+FileNamesTable*
+UTIL_createFNT_fromROTable(const char** filenames, size_t nbFilenames);
/*! UTIL_allocateFileNamesTable() :
* Allocates a table of const char*, to insert read-only names later on.
void UTIL_refFilename(FileNamesTable* fnt, const char* filename);
+/* UTIL_createExpandedFNT() is only active if UTIL_HAS_CREATEFILELIST is defined.
+ * Otherwise, UTIL_createExpandedFNT() is a shell function which does nothing
+ * apart from displaying a warning message.
+ */
+#ifdef _WIN32
+# define UTIL_HAS_CREATEFILELIST
+#elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */
+# define UTIL_HAS_CREATEFILELIST
+#else
+ /* do not define UTIL_HAS_CREATEFILELIST */
+#endif
+
+/*! UTIL_createExpandedFNT() :
+ * read names from @filenames, and expand those corresponding to directories.
+ * links are followed or not depending on @followLinks directive.
+ * @return : an expanded FileNamesTable*, where each name is a file
+ * or NULL in case of error
+ */
+FileNamesTable*
+UTIL_createExpandedFNT(const char** filenames, size_t nbFilenames, int followLinks);
+
+
/*-****************************************
* System
******************************************/