Przemyslaw Skibinski | 7a8a03c | 2016-12-21 15:08:44 +0100 | [diff] [blame] | 1 | /** |
| 2 | * util.h - utility functions |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 3 | * |
Przemyslaw Skibinski | 7a8a03c | 2016-12-21 15:08:44 +0100 | [diff] [blame] | 4 | * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * This source code is licensed under the BSD-style license found in the |
| 8 | * LICENSE file in the root directory of this source tree. An additional grant |
| 9 | * of patent rights can be found in the PATENTS file in the same directory. |
| 10 | */ |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 11 | |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 12 | #ifndef UTIL_H_MODULE |
| 13 | #define UTIL_H_MODULE |
| 14 | |
| 15 | #if defined (__cplusplus) |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
inikep | 9c22e57 | 2016-05-05 11:53:42 +0200 | [diff] [blame] | 19 | |
Przemyslaw Skibinski | 2f6ccee | 2016-12-21 13:23:34 +0100 | [diff] [blame] | 20 | |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 21 | /*-**************************************** |
| 22 | * Dependencies |
| 23 | ******************************************/ |
Przemyslaw Skibinski | 2f6ccee | 2016-12-21 13:23:34 +0100 | [diff] [blame] | 24 | #include "platform.h" /* PLATFORM_POSIX_VERSION */ |
| 25 | #include <stdlib.h> /* malloc */ |
| 26 | #include <stddef.h> /* size_t, ptrdiff_t */ |
| 27 | #include <stdio.h> /* fprintf */ |
| 28 | #include <sys/types.h> /* stat, utime */ |
| 29 | #include <sys/stat.h> /* stat */ |
Przemyslaw Skibinski | b40884f | 2016-11-03 09:54:53 +0100 | [diff] [blame] | 30 | #if defined(_MSC_VER) |
Przemyslaw Skibinski | 2f6ccee | 2016-12-21 13:23:34 +0100 | [diff] [blame] | 31 | # include <sys/utime.h> /* utime */ |
| 32 | # include <io.h> /* _chmod */ |
Przemyslaw Skibinski | b40884f | 2016-11-03 09:54:53 +0100 | [diff] [blame] | 33 | #else |
Yann Collet | fda539f | 2016-12-12 01:03:23 +0100 | [diff] [blame] | 34 | # include <unistd.h> /* chown, stat */ |
| 35 | # include <utime.h> /* utime */ |
Przemyslaw Skibinski | b40884f | 2016-11-03 09:54:53 +0100 | [diff] [blame] | 36 | #endif |
Przemyslaw Skibinski | 2f6ccee | 2016-12-21 13:23:34 +0100 | [diff] [blame] | 37 | #include <time.h> /* time */ |
Przemyslaw Skibinski | b40884f | 2016-11-03 09:54:53 +0100 | [diff] [blame] | 38 | #include <errno.h> |
Przemyslaw Skibinski | 2f6ccee | 2016-12-21 13:23:34 +0100 | [diff] [blame] | 39 | #include "mem.h" /* U32, U64 */ |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 40 | |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 41 | |
Przemyslaw Skibinski | 6e59b3c | 2017-02-15 17:03:16 +0100 | [diff] [blame] | 42 | /* ************************************************************ |
| 43 | * Avoid fseek()'s 2GiB barrier with MSVC, MacOS, *BSD, MinGW |
| 44 | ***************************************************************/ |
| 45 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 46 | # define UTIL_fseek _fseeki64 |
| 47 | #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ |
| 48 | # define UTIL_fseek fseeko |
| 49 | #elif defined(__MINGW32__) && defined(__MSVCRT__) && !defined(__STRICT_ANSI__) && !defined(__NO_MINGW_LFS) |
| 50 | # define UTIL_fseek fseeko64 |
| 51 | #else |
| 52 | # define UTIL_fseek fseek |
| 53 | #endif |
| 54 | |
| 55 | |
inikep | 9c22e57 | 2016-05-05 11:53:42 +0200 | [diff] [blame] | 56 | /*-**************************************** |
| 57 | * Sleep functions: Windows - Posix - others |
| 58 | ******************************************/ |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 59 | #if defined(_WIN32) |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 60 | # include <windows.h> |
Przemyslaw Skibinski | 94abd6a | 2017-02-07 16:36:19 +0100 | [diff] [blame] | 61 | # define SET_REALTIME_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 62 | # define UTIL_sleep(s) Sleep(1000*s) |
| 63 | # define UTIL_sleepMilli(milli) Sleep(milli) |
Przemyslaw Skibinski | b0f3663 | 2016-12-16 15:41:18 +0100 | [diff] [blame] | 64 | #elif PLATFORM_POSIX_VERSION >= 0 /* Unix-like operating system */ |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 65 | # include <unistd.h> |
| 66 | # include <sys/resource.h> /* setpriority */ |
| 67 | # include <time.h> /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */ |
Peter (Stig) Edwards | 04773ac | 2016-05-21 12:15:48 +0100 | [diff] [blame] | 68 | # if defined(PRIO_PROCESS) |
Przemyslaw Skibinski | 94abd6a | 2017-02-07 16:36:19 +0100 | [diff] [blame] | 69 | # define SET_REALTIME_PRIORITY setpriority(PRIO_PROCESS, 0, -20) |
Peter (Stig) Edwards | 04773ac | 2016-05-21 12:15:48 +0100 | [diff] [blame] | 70 | # else |
Przemyslaw Skibinski | 94abd6a | 2017-02-07 16:36:19 +0100 | [diff] [blame] | 71 | # define SET_REALTIME_PRIORITY /* disabled */ |
Peter (Stig) Edwards | 04773ac | 2016-05-21 12:15:48 +0100 | [diff] [blame] | 72 | # endif |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 73 | # define UTIL_sleep(s) sleep(s) |
Przemyslaw Skibinski | b0f3663 | 2016-12-16 15:41:18 +0100 | [diff] [blame] | 74 | # if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 199309L)) || (PLATFORM_POSIX_VERSION >= 200112L) /* nanosleep requires POSIX.1-2001 */ |
inikep | 9c22e57 | 2016-05-05 11:53:42 +0200 | [diff] [blame] | 75 | # define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); } |
| 76 | # else |
| 77 | # define UTIL_sleepMilli(milli) /* disabled */ |
| 78 | # endif |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 79 | #else |
Przemyslaw Skibinski | 94abd6a | 2017-02-07 16:36:19 +0100 | [diff] [blame] | 80 | # define SET_REALTIME_PRIORITY /* disabled */ |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 81 | # define UTIL_sleep(s) /* disabled */ |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 82 | # define UTIL_sleepMilli(milli) /* disabled */ |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 83 | #endif |
| 84 | |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 85 | |
Przemyslaw Skibinski | ead350b | 2016-12-21 09:04:59 +0100 | [diff] [blame] | 86 | /* ************************************* |
| 87 | * Constants |
| 88 | ***************************************/ |
| 89 | #define LIST_SIZE_INCREASE (8*1024) |
| 90 | |
| 91 | |
Przemyslaw Skibinski | ead350b | 2016-12-21 09:04:59 +0100 | [diff] [blame] | 92 | /*-**************************************** |
| 93 | * Compiler specifics |
| 94 | ******************************************/ |
Przemyslaw Skibinski | 2f6ccee | 2016-12-21 13:23:34 +0100 | [diff] [blame] | 95 | #if defined(__INTEL_COMPILER) |
| 96 | # pragma warning(disable : 177) /* disable: message #177: function was declared but never referenced, useful with UTIL_STATIC */ |
| 97 | #endif |
Przemyslaw Skibinski | ead350b | 2016-12-21 09:04:59 +0100 | [diff] [blame] | 98 | #if defined(__GNUC__) |
| 99 | # define UTIL_STATIC static __attribute__((unused)) |
| 100 | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) |
| 101 | # define UTIL_STATIC static inline |
| 102 | #elif defined(_MSC_VER) |
| 103 | # define UTIL_STATIC static __inline |
| 104 | #else |
| 105 | # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ |
| 106 | #endif |
| 107 | |
| 108 | |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 109 | /*-**************************************** |
| 110 | * Time functions |
| 111 | ******************************************/ |
Przemyslaw Skibinski | 83775d9 | 2017-02-20 11:11:50 +0100 | [diff] [blame] | 112 | #if defined(_WIN32) /* Windows */ |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 113 | typedef LARGE_INTEGER UTIL_freq_t; |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 114 | typedef LARGE_INTEGER UTIL_time_t; |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 115 | UTIL_STATIC void UTIL_initTimer(UTIL_freq_t* ticksPerSecond) { if (!QueryPerformanceFrequency(ticksPerSecond)) fprintf(stderr, "ERROR: QueryPerformance not present\n"); } |
inikep | aaaf923 | 2016-05-09 16:19:25 +0200 | [diff] [blame] | 116 | UTIL_STATIC void UTIL_getTime(UTIL_time_t* x) { QueryPerformanceCounter(x); } |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 117 | UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_freq_t ticksPerSecond, UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart; } |
| 118 | UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_freq_t ticksPerSecond, UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart; } |
Przemyslaw Skibinski | da4a0f3 | 2017-02-20 12:18:15 +0100 | [diff] [blame] | 119 | #elif defined(__APPLE__) && defined(__MACH__) |
| 120 | #include <mach/mach_time.h> |
| 121 | typedef mach_timebase_info_data_t UTIL_freq_t; |
| 122 | typedef U64 UTIL_time_t; |
Przemyslaw Skibinski | 74dcd8d | 2017-02-21 12:22:05 +0100 | [diff] [blame] | 123 | UTIL_STATIC void UTIL_initTimer(UTIL_freq_t* rate) { mach_timebase_info(rate); } |
Przemyslaw Skibinski | da4a0f3 | 2017-02-20 12:18:15 +0100 | [diff] [blame] | 124 | UTIL_STATIC void UTIL_getTime(UTIL_time_t* x) { *x = mach_absolute_time(); } |
| 125 | UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_freq_t rate, UTIL_time_t clockStart, UTIL_time_t clockEnd) { return (((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom))/1000ULL; } |
| 126 | UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_freq_t rate, UTIL_time_t clockStart, UTIL_time_t clockEnd) { return ((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom); } |
Przemyslaw Skibinski | 1b59333 | 2017-02-21 07:33:45 +0100 | [diff] [blame] | 127 | #elif (PLATFORM_POSIX_VERSION >= 200112L) |
| 128 | #include <sys/times.h> /* times */ |
| 129 | typedef U64 UTIL_freq_t; |
| 130 | typedef U64 UTIL_time_t; |
| 131 | UTIL_STATIC void UTIL_initTimer(UTIL_freq_t* ticksPerSecond) { *ticksPerSecond=sysconf(_SC_CLK_TCK); } |
| 132 | UTIL_STATIC void UTIL_getTime(UTIL_time_t* x) { struct tms junk; clock_t newTicks = (clock_t) times(&junk); (void)junk; *x = (UTIL_time_t)newTicks; } |
| 133 | UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_freq_t ticksPerSecond, UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / ticksPerSecond; } |
| 134 | UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_freq_t ticksPerSecond, UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000000ULL * (clockEnd - clockStart) / ticksPerSecond; } |
cyan4973 | 5fba09f | 2017-01-20 12:23:30 -0800 | [diff] [blame] | 135 | #else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */ |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 136 | typedef clock_t UTIL_freq_t; |
cyan4973 | 5fba09f | 2017-01-20 12:23:30 -0800 | [diff] [blame] | 137 | typedef clock_t UTIL_time_t; |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 138 | UTIL_STATIC void UTIL_initTimer(UTIL_freq_t* ticksPerSecond) { *ticksPerSecond=0; } |
cyan4973 | 5fba09f | 2017-01-20 12:23:30 -0800 | [diff] [blame] | 139 | UTIL_STATIC void UTIL_getTime(UTIL_time_t* x) { *x = clock(); } |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 140 | UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_freq_t ticksPerSecond, UTIL_time_t clockStart, UTIL_time_t clockEnd) { (void)ticksPerSecond; return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; } |
| 141 | UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_freq_t ticksPerSecond, UTIL_time_t clockStart, UTIL_time_t clockEnd) { (void)ticksPerSecond; return 1000000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; } |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 142 | #endif |
| 143 | |
| 144 | |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 145 | /* returns time span in microseconds */ |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 146 | UTIL_STATIC U64 UTIL_clockSpanMicro( UTIL_time_t clockStart, UTIL_freq_t ticksPerSecond ) |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 147 | { |
| 148 | UTIL_time_t clockEnd; |
inikep | aaaf923 | 2016-05-09 16:19:25 +0200 | [diff] [blame] | 149 | UTIL_getTime(&clockEnd); |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 150 | return UTIL_getSpanTimeMicro(ticksPerSecond, clockStart, clockEnd); |
| 151 | } |
| 152 | |
| 153 | |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 154 | UTIL_STATIC void UTIL_waitForNextTick(UTIL_freq_t ticksPerSecond) |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 155 | { |
| 156 | UTIL_time_t clockStart, clockEnd; |
inikep | aaaf923 | 2016-05-09 16:19:25 +0200 | [diff] [blame] | 157 | UTIL_getTime(&clockStart); |
Yann Collet | e162ace | 2016-05-20 11:24:35 +0200 | [diff] [blame] | 158 | do { |
| 159 | UTIL_getTime(&clockEnd); |
inikep | d5ff2c3 | 2016-04-28 14:40:45 +0200 | [diff] [blame] | 160 | } while (UTIL_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) == 0); |
inikep | 83c76b4 | 2016-04-28 13:16:01 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 164 | |
| 165 | /*-**************************************** |
| 166 | * File functions |
| 167 | ******************************************/ |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 168 | #if defined(_MSC_VER) |
Przemyslaw Skibinski | b40884f | 2016-11-03 09:54:53 +0100 | [diff] [blame] | 169 | #define chmod _chmod |
- | 7ec315d | 2017-02-10 13:27:43 +0100 | [diff] [blame] | 170 | typedef struct __stat64 stat_t; |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 171 | #else |
| 172 | typedef struct stat stat_t; |
| 173 | #endif |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 174 | |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 175 | |
| 176 | UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) |
| 177 | { |
| 178 | int res = 0; |
| 179 | struct utimbuf timebuf; |
| 180 | |
Przemyslaw Skibinski | b40884f | 2016-11-03 09:54:53 +0100 | [diff] [blame] | 181 | timebuf.actime = time(NULL); |
| 182 | timebuf.modtime = statbuf->st_mtime; |
| 183 | res += utime(filename, &timebuf); /* set access and modification times */ |
| 184 | |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 185 | #if !defined(_WIN32) |
| 186 | res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */ |
| 187 | #endif |
| 188 | |
| 189 | res += chmod(filename, statbuf->st_mode & 07777); /* Copy file permissions */ |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 190 | |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 191 | errno = 0; |
| 192 | return -res; /* number of errors is returned */ |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 196 | UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 197 | { |
| 198 | int r; |
| 199 | #if defined(_MSC_VER) |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 200 | r = _stat64(infilename, statbuf); |
| 201 | if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 202 | #else |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 203 | r = stat(infilename, statbuf); |
| 204 | if (r || !S_ISREG(statbuf->st_mode)) return 0; /* No good... */ |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 205 | #endif |
Przemyslaw Skibinski | fcf22e3 | 2016-11-02 14:08:07 +0100 | [diff] [blame] | 206 | return 1; |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Przemyslaw Skibinski | 442c75f | 2017-02-14 09:38:51 +0100 | [diff] [blame] | 209 | |
Sean Purcell | 0f5c95a | 2017-02-07 16:33:48 -0800 | [diff] [blame] | 210 | UTIL_STATIC int UTIL_isRegFile(const char* infilename) |
| 211 | { |
| 212 | stat_t statbuf; |
| 213 | return UTIL_getFileStat(infilename, &statbuf); /* Only need to know whether it is a regular file */ |
| 214 | } |
Przemyslaw Skibinski | d872b64 | 2016-11-02 12:52:20 +0100 | [diff] [blame] | 215 | |
Przemyslaw Skibinski | 442c75f | 2017-02-14 09:38:51 +0100 | [diff] [blame] | 216 | |
| 217 | UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) |
| 218 | { |
| 219 | int r; |
| 220 | stat_t statbuf; |
| 221 | #if defined(_MSC_VER) |
| 222 | r = _stat64(infilename, &statbuf); |
| 223 | if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; |
| 224 | #else |
| 225 | r = stat(infilename, &statbuf); |
| 226 | if (!r && S_ISDIR(statbuf.st_mode)) return 1; |
| 227 | #endif |
| 228 | return 0; |
| 229 | } |
| 230 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 231 | UTIL_STATIC U32 UTIL_isLink(const char* infilename) |
| 232 | { |
| 233 | #if defined(_WIN32) |
| 234 | /* no symlinks on windows */ |
| 235 | (void)infilename; |
| 236 | #else |
| 237 | int r; |
| 238 | stat_t statbuf; |
| 239 | r = lstat(infilename, &statbuf); |
| 240 | if (!r && S_ISLNK(statbuf.st_mode)) return 1; |
| 241 | #endif |
| 242 | return 0; |
| 243 | } |
| 244 | |
Przemyslaw Skibinski | 442c75f | 2017-02-14 09:38:51 +0100 | [diff] [blame] | 245 | |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 246 | UTIL_STATIC U64 UTIL_getFileSize(const char* infilename) |
| 247 | { |
| 248 | int r; |
| 249 | #if defined(_MSC_VER) |
Przemyslaw Skibinski | 35bf23c | 2017-02-13 13:57:29 +0100 | [diff] [blame] | 250 | struct __stat64 statbuf; |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 251 | r = _stat64(infilename, &statbuf); |
| 252 | if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ |
ds77 | 45f0c20 | 2017-02-10 18:37:57 +0100 | [diff] [blame] | 253 | #elif defined(__MINGW32__) && defined (__MSVCRT__) |
| 254 | struct _stati64 statbuf; |
| 255 | r = _stati64(infilename, &statbuf); |
| 256 | if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 257 | #else |
| 258 | struct stat statbuf; |
| 259 | r = stat(infilename, &statbuf); |
| 260 | if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */ |
| 261 | #endif |
| 262 | return (U64)statbuf.st_size; |
| 263 | } |
| 264 | |
| 265 | |
inikep | 55d047a | 2016-04-28 16:50:13 +0200 | [diff] [blame] | 266 | UTIL_STATIC U64 UTIL_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles) |
| 267 | { |
| 268 | U64 total = 0; |
| 269 | unsigned n; |
| 270 | for (n=0; n<nbFiles; n++) |
| 271 | total += UTIL_getFileSize(fileNamesTable[n]); |
| 272 | return total; |
| 273 | } |
| 274 | |
| 275 | |
inikep | 6173931 | 2016-09-15 18:58:18 +0200 | [diff] [blame] | 276 | /* |
| 277 | * A modified version of realloc(). |
| 278 | * If UTIL_realloc() fails the original block is freed. |
| 279 | */ |
| 280 | UTIL_STATIC void *UTIL_realloc(void *ptr, size_t size) |
| 281 | { |
| 282 | void *newptr = realloc(ptr, size); |
| 283 | if (newptr) return newptr; |
| 284 | free(ptr); |
| 285 | return NULL; |
| 286 | } |
| 287 | |
Sean Purcell | dee08ca | 2017-03-23 12:09:35 -0700 | [diff] [blame^] | 288 | static int g_utilDisplayLevel; |
| 289 | #define UTIL_DISPLAY(...) fprintf(stderr, __VA_ARGS__) |
| 290 | #define UTIL_DISPLAYLEVEL(l, ...) { if (g_utilDisplayLevel>=l) { UTIL_DISPLAY(__VA_ARGS__); } } |
| 291 | |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 292 | #ifdef _WIN32 |
inikep | 9c22e57 | 2016-05-05 11:53:42 +0200 | [diff] [blame] | 293 | # define UTIL_HAS_CREATEFILELIST |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 294 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 295 | UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks) |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 296 | { |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 297 | char* path; |
| 298 | int dirLength, fnameLength, pathLength, nbFiles = 0; |
Przemyslaw Skibinski | acb6e57 | 2017-02-15 17:13:35 +0100 | [diff] [blame] | 299 | WIN32_FIND_DATAA cFile; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 300 | HANDLE hFile; |
| 301 | |
inikep | 9f25fcf | 2016-09-13 16:38:54 +0200 | [diff] [blame] | 302 | dirLength = (int)strlen(dirName); |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 303 | path = (char*) malloc(dirLength + 3); |
| 304 | if (!path) return 0; |
| 305 | |
| 306 | memcpy(path, dirName, dirLength); |
| 307 | path[dirLength] = '\\'; |
| 308 | path[dirLength+1] = '*'; |
| 309 | path[dirLength+2] = 0; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 310 | |
Przemyslaw Skibinski | acb6e57 | 2017-02-15 17:13:35 +0100 | [diff] [blame] | 311 | hFile=FindFirstFileA(path, &cFile); |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 312 | if (hFile == INVALID_HANDLE_VALUE) { |
| 313 | fprintf(stderr, "Cannot open directory '%s'\n", dirName); |
| 314 | return 0; |
| 315 | } |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 316 | free(path); |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 317 | |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 318 | do { |
inikep | 9f25fcf | 2016-09-13 16:38:54 +0200 | [diff] [blame] | 319 | fnameLength = (int)strlen(cFile.cFileName); |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 320 | path = (char*) malloc(dirLength + fnameLength + 2); |
| 321 | if (!path) { FindClose(hFile); return 0; } |
| 322 | memcpy(path, dirName, dirLength); |
| 323 | path[dirLength] = '\\'; |
| 324 | memcpy(path+dirLength+1, cFile.cFileName, fnameLength); |
| 325 | pathLength = dirLength+1+fnameLength; |
| 326 | path[pathLength] = 0; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 327 | if (cFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 328 | if (strcmp (cFile.cFileName, "..") == 0 || |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 329 | strcmp (cFile.cFileName, ".") == 0) continue; |
inikep | e416e30 | 2016-08-24 17:32:09 +0200 | [diff] [blame] | 330 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 331 | nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */ |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 332 | if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 333 | } |
| 334 | else if ((cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)) { |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 335 | if (*bufStart + *pos + pathLength >= *bufEnd) { |
| 336 | ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE; |
inikep | 6173931 | 2016-09-15 18:58:18 +0200 | [diff] [blame] | 337 | *bufStart = (char*)UTIL_realloc(*bufStart, newListSize); |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 338 | *bufEnd = *bufStart + newListSize; |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 339 | if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; } |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 340 | } |
| 341 | if (*bufStart + *pos + pathLength < *bufEnd) { |
| 342 | strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos)); |
| 343 | *pos += pathLength + 1; |
| 344 | nbFiles++; |
| 345 | } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 346 | } |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 347 | free(path); |
Przemyslaw Skibinski | acb6e57 | 2017-02-15 17:13:35 +0100 | [diff] [blame] | 348 | } while (FindNextFileA(hFile, &cFile)); |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 349 | |
| 350 | FindClose(hFile); |
| 351 | return nbFiles; |
| 352 | } |
| 353 | |
Przemyslaw Skibinski | 0b37205 | 2016-12-16 17:12:23 +0100 | [diff] [blame] | 354 | #elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */ |
inikep | 9c22e57 | 2016-05-05 11:53:42 +0200 | [diff] [blame] | 355 | # define UTIL_HAS_CREATEFILELIST |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 356 | # include <dirent.h> /* opendir, readdir */ |
Przemyslaw Skibinski | ead350b | 2016-12-21 09:04:59 +0100 | [diff] [blame] | 357 | # include <string.h> /* strerror, memcpy */ |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 358 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 359 | UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks) |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 360 | { |
| 361 | DIR *dir; |
| 362 | struct dirent *entry; |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 363 | char* path; |
| 364 | int dirLength, fnameLength, pathLength, nbFiles = 0; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 365 | |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 366 | if (!(dir = opendir(dirName))) { |
| 367 | fprintf(stderr, "Cannot open directory '%s': %s\n", dirName, strerror(errno)); |
| 368 | return 0; |
| 369 | } |
Yann Collet | e162ace | 2016-05-20 11:24:35 +0200 | [diff] [blame] | 370 | |
inikep | 9f25fcf | 2016-09-13 16:38:54 +0200 | [diff] [blame] | 371 | dirLength = (int)strlen(dirName); |
inikep | 7bc5c6b | 2016-07-26 11:07:37 +0200 | [diff] [blame] | 372 | errno = 0; |
inikep | 3eabe9b | 2016-05-12 17:15:41 +0200 | [diff] [blame] | 373 | while ((entry = readdir(dir)) != NULL) { |
inikep | 0bd0fae | 2016-05-05 13:10:57 +0200 | [diff] [blame] | 374 | if (strcmp (entry->d_name, "..") == 0 || |
| 375 | strcmp (entry->d_name, ".") == 0) continue; |
inikep | 9f25fcf | 2016-09-13 16:38:54 +0200 | [diff] [blame] | 376 | fnameLength = (int)strlen(entry->d_name); |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 377 | path = (char*) malloc(dirLength + fnameLength + 2); |
| 378 | if (!path) { closedir(dir); return 0; } |
| 379 | memcpy(path, dirName, dirLength); |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 380 | |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 381 | path[dirLength] = '/'; |
| 382 | memcpy(path+dirLength+1, entry->d_name, fnameLength); |
| 383 | pathLength = dirLength+1+fnameLength; |
| 384 | path[pathLength] = 0; |
| 385 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 386 | if (!followLinks && UTIL_isLink(path)) { |
| 387 | UTIL_DISPLAYLEVEL(2, "Warning : %s is a symbolic link, ignoring\n", path); |
| 388 | continue; |
| 389 | } |
| 390 | |
inikep | 0bd0fae | 2016-05-05 13:10:57 +0200 | [diff] [blame] | 391 | if (UTIL_isDirectory(path)) { |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 392 | nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */ |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 393 | if (*bufStart == NULL) { free(path); closedir(dir); return 0; } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 394 | } else { |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 395 | if (*bufStart + *pos + pathLength >= *bufEnd) { |
| 396 | ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE; |
inikep | 6173931 | 2016-09-15 18:58:18 +0200 | [diff] [blame] | 397 | *bufStart = (char*)UTIL_realloc(*bufStart, newListSize); |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 398 | *bufEnd = *bufStart + newListSize; |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 399 | if (*bufStart == NULL) { free(path); closedir(dir); return 0; } |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 400 | } |
| 401 | if (*bufStart + *pos + pathLength < *bufEnd) { |
| 402 | strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos)); |
| 403 | *pos += pathLength + 1; |
| 404 | nbFiles++; |
| 405 | } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 406 | } |
inikep | 1c5ba8a | 2016-09-13 13:13:10 +0200 | [diff] [blame] | 407 | free(path); |
inikep | e416e30 | 2016-08-24 17:32:09 +0200 | [diff] [blame] | 408 | errno = 0; /* clear errno after UTIL_isDirectory, UTIL_prepareFileList */ |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 409 | } |
| 410 | |
inikep | 7bc5c6b | 2016-07-26 11:07:37 +0200 | [diff] [blame] | 411 | if (errno != 0) { |
| 412 | fprintf(stderr, "readdir(%s) error: %s\n", dirName, strerror(errno)); |
| 413 | free(*bufStart); |
| 414 | *bufStart = NULL; |
| 415 | } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 416 | closedir(dir); |
| 417 | return nbFiles; |
| 418 | } |
| 419 | |
| 420 | #else |
| 421 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 422 | UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks) |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 423 | { |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 424 | (void)bufStart; (void)bufEnd; (void)pos; |
Przemyslaw Skibinski | ead350b | 2016-12-21 09:04:59 +0100 | [diff] [blame] | 425 | fprintf(stderr, "Directory %s ignored (compiled without _WIN32 or _POSIX_C_SOURCE)\n", dirName); |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | |
inikep | e416e30 | 2016-08-24 17:32:09 +0200 | [diff] [blame] | 429 | #endif /* #ifdef _WIN32 */ |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 430 | |
Yann Collet | e162ace | 2016-05-20 11:24:35 +0200 | [diff] [blame] | 431 | /* |
| 432 | * UTIL_createFileList - takes a list of files and directories (params: inputNames, inputNamesNb), scans directories, |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 433 | * and returns a new list of files (params: return value, allocatedBuffer, allocatedNamesNb). |
| 434 | * After finishing usage of the list the structures should be freed with UTIL_freeFileList(params: return value, allocatedBuffer) |
| 435 | * In case of error UTIL_createFileList returns NULL and UTIL_freeFileList should not be called. |
| 436 | */ |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 437 | UTIL_STATIC const char** UTIL_createFileList(const char **inputNames, unsigned inputNamesNb, char** allocatedBuffer, unsigned* allocatedNamesNb, int followLinks) |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 438 | { |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 439 | size_t pos; |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 440 | unsigned i, nbFiles; |
Yann Collet | fda539f | 2016-12-12 01:03:23 +0100 | [diff] [blame] | 441 | char* buf = (char*)malloc(LIST_SIZE_INCREASE); |
| 442 | char* bufend = buf + LIST_SIZE_INCREASE; |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 443 | const char** fileTable; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 444 | |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 445 | if (!buf) return NULL; |
inikep | 9c22e57 | 2016-05-05 11:53:42 +0200 | [diff] [blame] | 446 | |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 447 | for (i=0, pos=0, nbFiles=0; i<inputNamesNb; i++) { |
inikep | 957823f | 2016-05-25 15:30:55 +0200 | [diff] [blame] | 448 | if (!UTIL_isDirectory(inputNames[i])) { |
Yann Collet | fda539f | 2016-12-12 01:03:23 +0100 | [diff] [blame] | 449 | size_t const len = strlen(inputNames[i]); |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 450 | if (buf + pos + len >= bufend) { |
| 451 | ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE; |
inikep | 6173931 | 2016-09-15 18:58:18 +0200 | [diff] [blame] | 452 | buf = (char*)UTIL_realloc(buf, newListSize); |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 453 | bufend = buf + newListSize; |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 454 | if (!buf) return NULL; |
inikep | 4dbf7f4 | 2016-05-11 14:11:00 +0200 | [diff] [blame] | 455 | } |
| 456 | if (buf + pos + len < bufend) { |
| 457 | strncpy(buf + pos, inputNames[i], bufend - (buf + pos)); |
| 458 | pos += len + 1; |
| 459 | nbFiles++; |
| 460 | } |
Yann Collet | 415251c | 2016-08-01 14:26:49 +0200 | [diff] [blame] | 461 | } else { |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 462 | nbFiles += UTIL_prepareFileList(inputNames[i], &buf, &pos, &bufend, followLinks); |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 463 | if (buf == NULL) return NULL; |
Yann Collet | 415251c | 2016-08-01 14:26:49 +0200 | [diff] [blame] | 464 | } } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 465 | |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 466 | if (nbFiles == 0) { free(buf); return NULL; } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 467 | |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 468 | fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*)); |
| 469 | if (!fileTable) { free(buf); return NULL; } |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 470 | |
Yann Collet | fda539f | 2016-12-12 01:03:23 +0100 | [diff] [blame] | 471 | for (i=0, pos=0; i<nbFiles; i++) { |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 472 | fileTable[i] = buf + pos; |
| 473 | pos += strlen(fileTable[i]) + 1; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 474 | } |
| 475 | |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 476 | if (buf + pos > bufend) { free(buf); free((void*)fileTable); return NULL; } |
| 477 | |
| 478 | *allocatedBuffer = buf; |
| 479 | *allocatedNamesNb = nbFiles; |
| 480 | |
| 481 | return fileTable; |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 485 | UTIL_STATIC void UTIL_freeFileList(const char** filenameTable, char* allocatedBuffer) |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 486 | { |
inikep | 0bdb6a8 | 2016-05-13 10:52:02 +0200 | [diff] [blame] | 487 | if (allocatedBuffer) free(allocatedBuffer); |
| 488 | if (filenameTable) free((void*)filenameTable); |
inikep | 3163403 | 2016-05-05 00:25:38 +0200 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | |
inikep | 69fcd7c | 2016-04-28 12:23:33 +0200 | [diff] [blame] | 492 | #if defined (__cplusplus) |
| 493 | } |
| 494 | #endif |
| 495 | |
| 496 | #endif /* UTIL_H_MODULE */ |