blob: 4f22236a91eccf774dc1d7ab82a6167fe1d2a2c9 [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
Yann Collet232d62b2017-08-21 11:24:32 -07002 * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
Przemyslaw Skibinski7a8a03c2016-12-21 15:08:44 +01003 * All rights reserved.
4 *
Yann Collet32fb4072017-08-18 16:52:05 -07005 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
Yann Collet3128e032017-09-08 00:09:23 -07008 * You may select, at your option, one of the above-listed licenses.
Przemyslaw Skibinski7a8a03c2016-12-21 15:08:44 +01009 */
inikep69fcd7c2016-04-28 12:23:33 +020010
inikep69fcd7c2016-04-28 12:23:33 +020011#ifndef UTIL_H_MODULE
12#define UTIL_H_MODULE
13
14#if defined (__cplusplus)
15extern "C" {
16#endif
17
inikep9c22e572016-05-05 11:53:42 +020018
Przemyslaw Skibinski2f6ccee2016-12-21 13:23:34 +010019
inikep69fcd7c2016-04-28 12:23:33 +020020/*-****************************************
21* Dependencies
22******************************************/
Przemyslaw Skibinski2f6ccee2016-12-21 13:23:34 +010023#include "platform.h" /* PLATFORM_POSIX_VERSION */
24#include <stdlib.h> /* malloc */
25#include <stddef.h> /* size_t, ptrdiff_t */
26#include <stdio.h> /* fprintf */
Sean Purcellafa48512017-04-13 12:28:28 -070027#include <string.h> /* strncmp */
Przemyslaw Skibinski2f6ccee2016-12-21 13:23:34 +010028#include <sys/types.h> /* stat, utime */
29#include <sys/stat.h> /* stat */
Przemyslaw Skibinskib40884f2016-11-03 09:54:53 +010030#if defined(_MSC_VER)
Przemyslaw Skibinski2f6ccee2016-12-21 13:23:34 +010031# include <sys/utime.h> /* utime */
32# include <io.h> /* _chmod */
Przemyslaw Skibinskib40884f2016-11-03 09:54:53 +010033#else
Yann Colletfda539f2016-12-12 01:03:23 +010034# include <unistd.h> /* chown, stat */
35# include <utime.h> /* utime */
Przemyslaw Skibinskib40884f2016-11-03 09:54:53 +010036#endif
Yann Collet00974692017-12-04 16:02:42 -080037#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
Przemyslaw Skibinskib40884f2016-11-03 09:54:53 +010038#include <errno.h>
Przemyslaw Skibinski2f6ccee2016-12-21 13:23:34 +010039#include "mem.h" /* U32, U64 */
inikep69fcd7c2016-04-28 12:23:33 +020040
inikep31634032016-05-05 00:25:38 +020041
Przemyslaw Skibinski6e59b3c2017-02-15 17:03:16 +010042/* ************************************************************
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
inikep9c22e572016-05-05 11:53:42 +020056/*-****************************************
57* Sleep functions: Windows - Posix - others
58******************************************/
inikep31634032016-05-05 00:25:38 +020059#if defined(_WIN32)
inikep83c76b42016-04-28 13:16:01 +020060# include <windows.h>
Przemyslaw Skibinski94abd6a2017-02-07 16:36:19 +010061# define SET_REALTIME_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
inikep83c76b42016-04-28 13:16:01 +020062# define UTIL_sleep(s) Sleep(1000*s)
63# define UTIL_sleepMilli(milli) Sleep(milli)
Przemyslaw Skibinskib0f36632016-12-16 15:41:18 +010064#elif PLATFORM_POSIX_VERSION >= 0 /* Unix-like operating system */
inikep31634032016-05-05 00:25:38 +020065# include <unistd.h>
66# include <sys/resource.h> /* setpriority */
Peter (Stig) Edwards04773ac2016-05-21 12:15:48 +010067# if defined(PRIO_PROCESS)
Przemyslaw Skibinski94abd6a2017-02-07 16:36:19 +010068# define SET_REALTIME_PRIORITY setpriority(PRIO_PROCESS, 0, -20)
Peter (Stig) Edwards04773ac2016-05-21 12:15:48 +010069# else
Przemyslaw Skibinski94abd6a2017-02-07 16:36:19 +010070# define SET_REALTIME_PRIORITY /* disabled */
Peter (Stig) Edwards04773ac2016-05-21 12:15:48 +010071# endif
inikep31634032016-05-05 00:25:38 +020072# define UTIL_sleep(s) sleep(s)
Przemyslaw Skibinskib0f36632016-12-16 15:41:18 +010073# if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 199309L)) || (PLATFORM_POSIX_VERSION >= 200112L) /* nanosleep requires POSIX.1-2001 */
inikep9c22e572016-05-05 11:53:42 +020074# define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); }
75# else
76# define UTIL_sleepMilli(milli) /* disabled */
77# endif
inikep83c76b42016-04-28 13:16:01 +020078#else
Przemyslaw Skibinski94abd6a2017-02-07 16:36:19 +010079# define SET_REALTIME_PRIORITY /* disabled */
inikep31634032016-05-05 00:25:38 +020080# define UTIL_sleep(s) /* disabled */
inikep83c76b42016-04-28 13:16:01 +020081# define UTIL_sleepMilli(milli) /* disabled */
inikep83c76b42016-04-28 13:16:01 +020082#endif
83
inikep31634032016-05-05 00:25:38 +020084
Przemyslaw Skibinskiead350b2016-12-21 09:04:59 +010085/* *************************************
86* Constants
87***************************************/
88#define LIST_SIZE_INCREASE (8*1024)
89
90
Przemyslaw Skibinskiead350b2016-12-21 09:04:59 +010091/*-****************************************
92* Compiler specifics
93******************************************/
Przemyslaw Skibinski2f6ccee2016-12-21 13:23:34 +010094#if defined(__INTEL_COMPILER)
95# pragma warning(disable : 177) /* disable: message #177: function was declared but never referenced, useful with UTIL_STATIC */
96#endif
Przemyslaw Skibinskiead350b2016-12-21 09:04:59 +010097#if defined(__GNUC__)
98# define UTIL_STATIC static __attribute__((unused))
99#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
100# define UTIL_STATIC static inline
101#elif defined(_MSC_VER)
102# define UTIL_STATIC static __inline
103#else
104# define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
105#endif
106
107
inikep31634032016-05-05 00:25:38 +0200108/*-****************************************
Yann Collet4299c272017-08-31 16:58:47 -0700109* Console log
110******************************************/
111static int g_utilDisplayLevel;
112#define UTIL_DISPLAY(...) fprintf(stderr, __VA_ARGS__)
113#define UTIL_DISPLAYLEVEL(l, ...) { if (g_utilDisplayLevel>=l) { UTIL_DISPLAY(__VA_ARGS__); } }
114
115
116/*-****************************************
inikep31634032016-05-05 00:25:38 +0200117* Time functions
118******************************************/
Przemyslaw Skibinski83775d92017-02-20 11:11:50 +0100119#if defined(_WIN32) /* Windows */
Nick Terrell9a2f6f42017-11-29 19:11:12 -0800120 #define UTIL_TIME_INITIALIZER { { 0, 0 } }
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700121 typedef LARGE_INTEGER UTIL_time_t;
Yann Colletc95c0c92017-09-12 18:12:46 -0700122 UTIL_STATIC UTIL_time_t UTIL_getTime(void) { UTIL_time_t x; QueryPerformanceCounter(&x); return x; }
123 UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd)
124 {
Yann Collet8f26dc32017-09-12 21:21:17 -0700125 static LARGE_INTEGER ticksPerSecond;
126 static int init = 0;
127 if (!init) {
Yann Colletc95c0c92017-09-12 18:12:46 -0700128 if (!QueryPerformanceFrequency(&ticksPerSecond))
129 UTIL_DISPLAYLEVEL(1, "ERROR: QueryPerformanceFrequency() failure\n");
Yann Collet8f26dc32017-09-12 21:21:17 -0700130 init = 1;
Yann Colletc95c0c92017-09-12 18:12:46 -0700131 }
132 return 1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
133 }
134 UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
135 {
Yann Collet8f26dc32017-09-12 21:21:17 -0700136 static LARGE_INTEGER ticksPerSecond;
137 static int init = 0;
138 if (!init) {
Yann Colletc95c0c92017-09-12 18:12:46 -0700139 if (!QueryPerformanceFrequency(&ticksPerSecond))
140 UTIL_DISPLAYLEVEL(1, "ERROR: QueryPerformanceFrequency() failure\n");
Yann Collet8f26dc32017-09-12 21:21:17 -0700141 init = 1;
Yann Colletc95c0c92017-09-12 18:12:46 -0700142 }
143 return 1000000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
144 }
Przemyslaw Skibinskida4a0f32017-02-20 12:18:15 +0100145#elif defined(__APPLE__) && defined(__MACH__)
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700146 #include <mach/mach_time.h>
Nick Terrell9a2f6f42017-11-29 19:11:12 -0800147 #define UTIL_TIME_INITIALIZER 0
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700148 typedef U64 UTIL_time_t;
Yann Colletc95c0c92017-09-12 18:12:46 -0700149 UTIL_STATIC UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); }
150 UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd)
151 {
152 static mach_timebase_info_data_t rate;
153 static int init = 0;
154 if (!init) {
155 mach_timebase_info(&rate);
156 init = 1;
157 }
158 return (((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom))/1000ULL;
159 }
160 UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
161 {
162 static mach_timebase_info_data_t rate;
163 static int init = 0;
164 if (!init) {
165 mach_timebase_info(&rate);
166 init = 1;
167 }
168 return ((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom);
169 }
Yann Collet31293332017-12-04 16:31:59 -0800170#elif (PLATFORM_POSIX_VERSION >= 200112L) && (defined __UCLIBC__ || ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2))
Nick Terrell9a2f6f42017-11-29 19:11:12 -0800171 #define UTIL_TIME_INITIALIZER { 0, 0 }
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700172 typedef struct timespec UTIL_freq_t;
173 typedef struct timespec UTIL_time_t;
Yann Colletc95c0c92017-09-12 18:12:46 -0700174 UTIL_STATIC UTIL_time_t UTIL_getTime(void)
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700175 {
Yann Colletc95c0c92017-09-12 18:12:46 -0700176 UTIL_time_t time;
177 if (clock_gettime(CLOCK_MONOTONIC, &time))
178 UTIL_DISPLAYLEVEL(1, "ERROR: Failed to get time\n"); /* we could also exit() */
179 return time;
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700180 }
Yann Colletc95c0c92017-09-12 18:12:46 -0700181 UTIL_STATIC UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end)
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700182 {
183 UTIL_time_t diff;
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700184 if (end.tv_nsec < begin.tv_nsec) {
185 diff.tv_sec = (end.tv_sec - 1) - begin.tv_sec;
186 diff.tv_nsec = (end.tv_nsec + 1000000000ULL) - begin.tv_nsec;
187 } else {
188 diff.tv_sec = end.tv_sec - begin.tv_sec;
189 diff.tv_nsec = end.tv_nsec - begin.tv_nsec;
190 }
191 return diff;
192 }
Yann Colletc95c0c92017-09-12 18:12:46 -0700193 UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t begin, UTIL_time_t end)
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700194 {
Yann Colletc95c0c92017-09-12 18:12:46 -0700195 UTIL_time_t const diff = UTIL_getSpanTime(begin, end);
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700196 U64 micro = 0;
197 micro += 1000000ULL * diff.tv_sec;
198 micro += diff.tv_nsec / 1000ULL;
199 return micro;
200 }
Yann Colletc95c0c92017-09-12 18:12:46 -0700201 UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_time_t begin, UTIL_time_t end)
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700202 {
Yann Colletc95c0c92017-09-12 18:12:46 -0700203 UTIL_time_t const diff = UTIL_getSpanTime(begin, end);
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700204 U64 nano = 0;
205 nano += 1000000000ULL * diff.tv_sec;
206 nano += diff.tv_nsec;
207 return nano;
208 }
cyan49735fba09f2017-01-20 12:23:30 -0800209#else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */
Nick Terrell6ab4d5e2017-09-12 13:09:08 -0700210 typedef clock_t UTIL_time_t;
Nick Terrell9a2f6f42017-11-29 19:11:12 -0800211 #define UTIL_TIME_INITIALIZER 0
Yann Colletc95c0c92017-09-12 18:12:46 -0700212 UTIL_STATIC UTIL_time_t UTIL_getTime(void) { return clock(); }
213 UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }
214 UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }
inikep83c76b42016-04-28 13:16:01 +0200215#endif
216
Nick Terrelldab8cfa2017-11-30 19:40:53 -0800217#define SEC_TO_MICRO 1000000
inikep83c76b42016-04-28 13:16:01 +0200218
inikep83c76b42016-04-28 13:16:01 +0200219/* returns time span in microseconds */
Yann Colletc95c0c92017-09-12 18:12:46 -0700220UTIL_STATIC U64 UTIL_clockSpanMicro( UTIL_time_t clockStart )
inikep83c76b42016-04-28 13:16:01 +0200221{
Yann Colletc95c0c92017-09-12 18:12:46 -0700222 UTIL_time_t const clockEnd = UTIL_getTime();
223 return UTIL_getSpanTimeMicro(clockStart, clockEnd);
inikep83c76b42016-04-28 13:16:01 +0200224}
225
226
Yann Colletbc41c7f2017-09-12 19:32:26 -0700227UTIL_STATIC void UTIL_waitForNextTick(void)
inikep83c76b42016-04-28 13:16:01 +0200228{
Yann Colletc95c0c92017-09-12 18:12:46 -0700229 UTIL_time_t const clockStart = UTIL_getTime();
230 UTIL_time_t clockEnd;
Yann Collete162ace2016-05-20 11:24:35 +0200231 do {
Yann Colletc95c0c92017-09-12 18:12:46 -0700232 clockEnd = UTIL_getTime();
233 } while (UTIL_getSpanTimeNano(clockStart, clockEnd) == 0);
inikep83c76b42016-04-28 13:16:01 +0200234}
235
236
inikep31634032016-05-05 00:25:38 +0200237
238/*-****************************************
239* File functions
240******************************************/
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100241#if defined(_MSC_VER)
Nick Terrell5152fb22017-03-29 18:51:58 -0700242 #define chmod _chmod
243 typedef struct __stat64 stat_t;
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100244#else
245 typedef struct stat stat_t;
246#endif
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100247
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100248
Nick Terrellfd631402018-01-05 11:44:25 -0800249UTIL_STATIC int UTIL_isRegularFile(const char* infilename);
250
251
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100252UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
253{
254 int res = 0;
255 struct utimbuf timebuf;
256
Nick Terrellfd631402018-01-05 11:44:25 -0800257 if (!UTIL_isRegularFile(filename))
258 return -1;
259
Nick Terrell5152fb22017-03-29 18:51:58 -0700260 timebuf.actime = time(NULL);
261 timebuf.modtime = statbuf->st_mtime;
262 res += utime(filename, &timebuf); /* set access and modification times */
Przemyslaw Skibinskib40884f2016-11-03 09:54:53 +0100263
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100264#if !defined(_WIN32)
265 res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */
266#endif
267
268 res += chmod(filename, statbuf->st_mode & 07777); /* Copy file permissions */
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100269
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100270 errno = 0;
271 return -res; /* number of errors is returned */
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100272}
273
274
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100275UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100276{
277 int r;
278#if defined(_MSC_VER)
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100279 r = _stat64(infilename, statbuf);
280 if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100281#else
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100282 r = stat(infilename, statbuf);
283 if (r || !S_ISREG(statbuf->st_mode)) return 0; /* No good... */
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100284#endif
Przemyslaw Skibinskifcf22e32016-11-02 14:08:07 +0100285 return 1;
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100286}
287
Przemyslaw Skibinski442c75f2017-02-14 09:38:51 +0100288
Yann Collet6d4fef32017-05-17 18:36:15 -0700289UTIL_STATIC int UTIL_isRegularFile(const char* infilename)
Sean Purcell0f5c95a2017-02-07 16:33:48 -0800290{
291 stat_t statbuf;
292 return UTIL_getFileStat(infilename, &statbuf); /* Only need to know whether it is a regular file */
293}
Przemyslaw Skibinskid872b642016-11-02 12:52:20 +0100294
Przemyslaw Skibinski442c75f2017-02-14 09:38:51 +0100295
296UTIL_STATIC U32 UTIL_isDirectory(const char* infilename)
297{
298 int r;
299 stat_t statbuf;
300#if defined(_MSC_VER)
301 r = _stat64(infilename, &statbuf);
302 if (!r && (statbuf.st_mode & _S_IFDIR)) return 1;
303#else
304 r = stat(infilename, &statbuf);
305 if (!r && S_ISDIR(statbuf.st_mode)) return 1;
306#endif
307 return 0;
308}
309
Sean Purcell680e4e02017-03-23 11:52:09 -0700310UTIL_STATIC U32 UTIL_isLink(const char* infilename)
311{
312#if defined(_WIN32)
313 /* no symlinks on windows */
314 (void)infilename;
315#else
316 int r;
317 stat_t statbuf;
318 r = lstat(infilename, &statbuf);
319 if (!r && S_ISLNK(statbuf.st_mode)) return 1;
320#endif
321 return 0;
322}
323
Przemyslaw Skibinski442c75f2017-02-14 09:38:51 +0100324
Yann Collet18b79532017-10-17 16:14:25 -0700325#define UTIL_FILESIZE_UNKNOWN ((U64)(-1))
inikep69fcd7c2016-04-28 12:23:33 +0200326UTIL_STATIC U64 UTIL_getFileSize(const char* infilename)
327{
Yann Collet18b79532017-10-17 16:14:25 -0700328 if (!UTIL_isRegularFile(infilename)) return UTIL_FILESIZE_UNKNOWN;
329 { int r;
inikep69fcd7c2016-04-28 12:23:33 +0200330#if defined(_MSC_VER)
Yann Collet18b79532017-10-17 16:14:25 -0700331 struct __stat64 statbuf;
332 r = _stat64(infilename, &statbuf);
333 if (r || !(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
ds7745f0c202017-02-10 18:37:57 +0100334#elif defined(__MINGW32__) && defined (__MSVCRT__)
Yann Collet18b79532017-10-17 16:14:25 -0700335 struct _stati64 statbuf;
336 r = _stati64(infilename, &statbuf);
337 if (r || !(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
inikep69fcd7c2016-04-28 12:23:33 +0200338#else
Yann Collet18b79532017-10-17 16:14:25 -0700339 struct stat statbuf;
340 r = stat(infilename, &statbuf);
341 if (r || !S_ISREG(statbuf.st_mode)) return UTIL_FILESIZE_UNKNOWN;
inikep69fcd7c2016-04-28 12:23:33 +0200342#endif
Yann Collet18b79532017-10-17 16:14:25 -0700343 return (U64)statbuf.st_size;
344 }
inikep69fcd7c2016-04-28 12:23:33 +0200345}
346
347
Yann Colletd898fb72017-11-17 00:22:55 -0800348UTIL_STATIC U64 UTIL_getTotalFileSize(const char* const * const fileNamesTable, unsigned nbFiles)
inikep55d047a2016-04-28 16:50:13 +0200349{
350 U64 total = 0;
Yann Collet18b79532017-10-17 16:14:25 -0700351 int error = 0;
inikep55d047a2016-04-28 16:50:13 +0200352 unsigned n;
Yann Collet18b79532017-10-17 16:14:25 -0700353 for (n=0; n<nbFiles; n++) {
354 U64 const size = UTIL_getFileSize(fileNamesTable[n]);
355 error |= (size == UTIL_FILESIZE_UNKNOWN);
356 total += size;
357 }
358 return error ? UTIL_FILESIZE_UNKNOWN : total;
inikep55d047a2016-04-28 16:50:13 +0200359}
360
361
inikep61739312016-09-15 18:58:18 +0200362/*
363 * A modified version of realloc().
364 * If UTIL_realloc() fails the original block is freed.
365*/
366UTIL_STATIC void *UTIL_realloc(void *ptr, size_t size)
367{
368 void *newptr = realloc(ptr, size);
369 if (newptr) return newptr;
370 free(ptr);
371 return NULL;
372}
373
inikep31634032016-05-05 00:25:38 +0200374#ifdef _WIN32
inikep9c22e572016-05-05 11:53:42 +0200375# define UTIL_HAS_CREATEFILELIST
inikep31634032016-05-05 00:25:38 +0200376
Sean Purcell680e4e02017-03-23 11:52:09 -0700377UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks)
inikep31634032016-05-05 00:25:38 +0200378{
inikep1c5ba8a2016-09-13 13:13:10 +0200379 char* path;
380 int dirLength, fnameLength, pathLength, nbFiles = 0;
Przemyslaw Skibinskiacb6e572017-02-15 17:13:35 +0100381 WIN32_FIND_DATAA cFile;
inikep31634032016-05-05 00:25:38 +0200382 HANDLE hFile;
383
inikep9f25fcf2016-09-13 16:38:54 +0200384 dirLength = (int)strlen(dirName);
inikep1c5ba8a2016-09-13 13:13:10 +0200385 path = (char*) malloc(dirLength + 3);
386 if (!path) return 0;
387
388 memcpy(path, dirName, dirLength);
389 path[dirLength] = '\\';
390 path[dirLength+1] = '*';
391 path[dirLength+2] = 0;
inikep31634032016-05-05 00:25:38 +0200392
Przemyslaw Skibinskiacb6e572017-02-15 17:13:35 +0100393 hFile=FindFirstFileA(path, &cFile);
inikep31634032016-05-05 00:25:38 +0200394 if (hFile == INVALID_HANDLE_VALUE) {
Yann Collet4299c272017-08-31 16:58:47 -0700395 UTIL_DISPLAYLEVEL(1, "Cannot open directory '%s'\n", dirName);
inikep31634032016-05-05 00:25:38 +0200396 return 0;
397 }
inikep1c5ba8a2016-09-13 13:13:10 +0200398 free(path);
inikep31634032016-05-05 00:25:38 +0200399
inikep4dbf7f42016-05-11 14:11:00 +0200400 do {
inikep9f25fcf2016-09-13 16:38:54 +0200401 fnameLength = (int)strlen(cFile.cFileName);
inikep1c5ba8a2016-09-13 13:13:10 +0200402 path = (char*) malloc(dirLength + fnameLength + 2);
403 if (!path) { FindClose(hFile); return 0; }
404 memcpy(path, dirName, dirLength);
405 path[dirLength] = '\\';
406 memcpy(path+dirLength+1, cFile.cFileName, fnameLength);
407 pathLength = dirLength+1+fnameLength;
408 path[pathLength] = 0;
inikep31634032016-05-05 00:25:38 +0200409 if (cFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
410 if (strcmp (cFile.cFileName, "..") == 0 ||
inikep4dbf7f42016-05-11 14:11:00 +0200411 strcmp (cFile.cFileName, ".") == 0) continue;
inikepe416e302016-08-24 17:32:09 +0200412
Sean Purcell680e4e02017-03-23 11:52:09 -0700413 nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */
inikep1c5ba8a2016-09-13 13:13:10 +0200414 if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
inikep31634032016-05-05 00:25:38 +0200415 }
416 else if ((cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)) {
inikep4dbf7f42016-05-11 14:11:00 +0200417 if (*bufStart + *pos + pathLength >= *bufEnd) {
418 ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
inikep61739312016-09-15 18:58:18 +0200419 *bufStart = (char*)UTIL_realloc(*bufStart, newListSize);
inikep4dbf7f42016-05-11 14:11:00 +0200420 *bufEnd = *bufStart + newListSize;
inikep1c5ba8a2016-09-13 13:13:10 +0200421 if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
inikep4dbf7f42016-05-11 14:11:00 +0200422 }
423 if (*bufStart + *pos + pathLength < *bufEnd) {
424 strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos));
425 *pos += pathLength + 1;
426 nbFiles++;
427 }
inikep31634032016-05-05 00:25:38 +0200428 }
inikep1c5ba8a2016-09-13 13:13:10 +0200429 free(path);
Przemyslaw Skibinskiacb6e572017-02-15 17:13:35 +0100430 } while (FindNextFileA(hFile, &cFile));
inikep31634032016-05-05 00:25:38 +0200431
432 FindClose(hFile);
433 return nbFiles;
434}
435
Przemyslaw Skibinski0b372052016-12-16 17:12:23 +0100436#elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */
inikep9c22e572016-05-05 11:53:42 +0200437# define UTIL_HAS_CREATEFILELIST
inikep31634032016-05-05 00:25:38 +0200438# include <dirent.h> /* opendir, readdir */
Przemyslaw Skibinskiead350b2016-12-21 09:04:59 +0100439# include <string.h> /* strerror, memcpy */
inikep31634032016-05-05 00:25:38 +0200440
Sean Purcell680e4e02017-03-23 11:52:09 -0700441UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks)
inikep31634032016-05-05 00:25:38 +0200442{
443 DIR *dir;
444 struct dirent *entry;
inikep1c5ba8a2016-09-13 13:13:10 +0200445 char* path;
446 int dirLength, fnameLength, pathLength, nbFiles = 0;
inikep31634032016-05-05 00:25:38 +0200447
inikep31634032016-05-05 00:25:38 +0200448 if (!(dir = opendir(dirName))) {
Yann Collet4299c272017-08-31 16:58:47 -0700449 UTIL_DISPLAYLEVEL(1, "Cannot open directory '%s': %s\n", dirName, strerror(errno));
inikep31634032016-05-05 00:25:38 +0200450 return 0;
451 }
Yann Collete162ace2016-05-20 11:24:35 +0200452
inikep9f25fcf2016-09-13 16:38:54 +0200453 dirLength = (int)strlen(dirName);
inikep7bc5c6b2016-07-26 11:07:37 +0200454 errno = 0;
inikep3eabe9b2016-05-12 17:15:41 +0200455 while ((entry = readdir(dir)) != NULL) {
inikep0bd0fae2016-05-05 13:10:57 +0200456 if (strcmp (entry->d_name, "..") == 0 ||
457 strcmp (entry->d_name, ".") == 0) continue;
inikep9f25fcf2016-09-13 16:38:54 +0200458 fnameLength = (int)strlen(entry->d_name);
inikep1c5ba8a2016-09-13 13:13:10 +0200459 path = (char*) malloc(dirLength + fnameLength + 2);
460 if (!path) { closedir(dir); return 0; }
461 memcpy(path, dirName, dirLength);
Sean Purcell680e4e02017-03-23 11:52:09 -0700462
inikep1c5ba8a2016-09-13 13:13:10 +0200463 path[dirLength] = '/';
464 memcpy(path+dirLength+1, entry->d_name, fnameLength);
465 pathLength = dirLength+1+fnameLength;
466 path[pathLength] = 0;
467
Sean Purcell680e4e02017-03-23 11:52:09 -0700468 if (!followLinks && UTIL_isLink(path)) {
469 UTIL_DISPLAYLEVEL(2, "Warning : %s is a symbolic link, ignoring\n", path);
470 continue;
471 }
472
inikep0bd0fae2016-05-05 13:10:57 +0200473 if (UTIL_isDirectory(path)) {
Sean Purcell680e4e02017-03-23 11:52:09 -0700474 nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */
inikep1c5ba8a2016-09-13 13:13:10 +0200475 if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
inikep31634032016-05-05 00:25:38 +0200476 } else {
inikep4dbf7f42016-05-11 14:11:00 +0200477 if (*bufStart + *pos + pathLength >= *bufEnd) {
478 ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
inikep61739312016-09-15 18:58:18 +0200479 *bufStart = (char*)UTIL_realloc(*bufStart, newListSize);
inikep4dbf7f42016-05-11 14:11:00 +0200480 *bufEnd = *bufStart + newListSize;
inikep1c5ba8a2016-09-13 13:13:10 +0200481 if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
inikep4dbf7f42016-05-11 14:11:00 +0200482 }
483 if (*bufStart + *pos + pathLength < *bufEnd) {
484 strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos));
485 *pos += pathLength + 1;
486 nbFiles++;
487 }
inikep31634032016-05-05 00:25:38 +0200488 }
inikep1c5ba8a2016-09-13 13:13:10 +0200489 free(path);
inikepe416e302016-08-24 17:32:09 +0200490 errno = 0; /* clear errno after UTIL_isDirectory, UTIL_prepareFileList */
inikep31634032016-05-05 00:25:38 +0200491 }
492
inikep7bc5c6b2016-07-26 11:07:37 +0200493 if (errno != 0) {
Yann Collet4299c272017-08-31 16:58:47 -0700494 UTIL_DISPLAYLEVEL(1, "readdir(%s) error: %s\n", dirName, strerror(errno));
inikep7bc5c6b2016-07-26 11:07:37 +0200495 free(*bufStart);
496 *bufStart = NULL;
497 }
inikep31634032016-05-05 00:25:38 +0200498 closedir(dir);
499 return nbFiles;
500}
501
502#else
503
Sean Purcell680e4e02017-03-23 11:52:09 -0700504UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks)
inikep31634032016-05-05 00:25:38 +0200505{
inikep4dbf7f42016-05-11 14:11:00 +0200506 (void)bufStart; (void)bufEnd; (void)pos;
Yann Collet4299c272017-08-31 16:58:47 -0700507 UTIL_DISPLAYLEVEL(1, "Directory %s ignored (compiled without _WIN32 or _POSIX_C_SOURCE)\n", dirName);
inikep31634032016-05-05 00:25:38 +0200508 return 0;
509}
510
inikepe416e302016-08-24 17:32:09 +0200511#endif /* #ifdef _WIN32 */
inikep31634032016-05-05 00:25:38 +0200512
Yann Collete162ace2016-05-20 11:24:35 +0200513/*
514 * UTIL_createFileList - takes a list of files and directories (params: inputNames, inputNamesNb), scans directories,
inikep0bdb6a82016-05-13 10:52:02 +0200515 * and returns a new list of files (params: return value, allocatedBuffer, allocatedNamesNb).
516 * After finishing usage of the list the structures should be freed with UTIL_freeFileList(params: return value, allocatedBuffer)
517 * In case of error UTIL_createFileList returns NULL and UTIL_freeFileList should not be called.
518 */
Sean Purcell680e4e02017-03-23 11:52:09 -0700519UTIL_STATIC const char** UTIL_createFileList(const char **inputNames, unsigned inputNamesNb, char** allocatedBuffer, unsigned* allocatedNamesNb, int followLinks)
inikep31634032016-05-05 00:25:38 +0200520{
inikep4dbf7f42016-05-11 14:11:00 +0200521 size_t pos;
inikep0bdb6a82016-05-13 10:52:02 +0200522 unsigned i, nbFiles;
Yann Colletfda539f2016-12-12 01:03:23 +0100523 char* buf = (char*)malloc(LIST_SIZE_INCREASE);
524 char* bufend = buf + LIST_SIZE_INCREASE;
inikep0bdb6a82016-05-13 10:52:02 +0200525 const char** fileTable;
inikep31634032016-05-05 00:25:38 +0200526
inikep0bdb6a82016-05-13 10:52:02 +0200527 if (!buf) return NULL;
inikep9c22e572016-05-05 11:53:42 +0200528
inikep0bdb6a82016-05-13 10:52:02 +0200529 for (i=0, pos=0, nbFiles=0; i<inputNamesNb; i++) {
inikep957823f2016-05-25 15:30:55 +0200530 if (!UTIL_isDirectory(inputNames[i])) {
Yann Colletfda539f2016-12-12 01:03:23 +0100531 size_t const len = strlen(inputNames[i]);
inikep4dbf7f42016-05-11 14:11:00 +0200532 if (buf + pos + len >= bufend) {
533 ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE;
inikep61739312016-09-15 18:58:18 +0200534 buf = (char*)UTIL_realloc(buf, newListSize);
inikep4dbf7f42016-05-11 14:11:00 +0200535 bufend = buf + newListSize;
inikep0bdb6a82016-05-13 10:52:02 +0200536 if (!buf) return NULL;
inikep4dbf7f42016-05-11 14:11:00 +0200537 }
538 if (buf + pos + len < bufend) {
539 strncpy(buf + pos, inputNames[i], bufend - (buf + pos));
540 pos += len + 1;
541 nbFiles++;
542 }
Yann Collet415251c2016-08-01 14:26:49 +0200543 } else {
Sean Purcell680e4e02017-03-23 11:52:09 -0700544 nbFiles += UTIL_prepareFileList(inputNames[i], &buf, &pos, &bufend, followLinks);
inikep0bdb6a82016-05-13 10:52:02 +0200545 if (buf == NULL) return NULL;
Yann Collet415251c2016-08-01 14:26:49 +0200546 } }
inikep31634032016-05-05 00:25:38 +0200547
inikep0bdb6a82016-05-13 10:52:02 +0200548 if (nbFiles == 0) { free(buf); return NULL; }
inikep31634032016-05-05 00:25:38 +0200549
inikep0bdb6a82016-05-13 10:52:02 +0200550 fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*));
551 if (!fileTable) { free(buf); return NULL; }
inikep31634032016-05-05 00:25:38 +0200552
Yann Colletfda539f2016-12-12 01:03:23 +0100553 for (i=0, pos=0; i<nbFiles; i++) {
inikep0bdb6a82016-05-13 10:52:02 +0200554 fileTable[i] = buf + pos;
555 pos += strlen(fileTable[i]) + 1;
inikep31634032016-05-05 00:25:38 +0200556 }
557
inikep0bdb6a82016-05-13 10:52:02 +0200558 if (buf + pos > bufend) { free(buf); free((void*)fileTable); return NULL; }
559
560 *allocatedBuffer = buf;
561 *allocatedNamesNb = nbFiles;
562
563 return fileTable;
inikep31634032016-05-05 00:25:38 +0200564}
565
566
inikep0bdb6a82016-05-13 10:52:02 +0200567UTIL_STATIC void UTIL_freeFileList(const char** filenameTable, char* allocatedBuffer)
inikep31634032016-05-05 00:25:38 +0200568{
inikep0bdb6a82016-05-13 10:52:02 +0200569 if (allocatedBuffer) free(allocatedBuffer);
570 if (filenameTable) free((void*)filenameTable);
inikep31634032016-05-05 00:25:38 +0200571}
572
Sean Purcellafa48512017-04-13 12:28:28 -0700573/* count the number of physical cores */
574#if defined(_WIN32) || defined(WIN32)
575
576#include <windows.h>
577
578typedef BOOL(WINAPI* LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
579
580UTIL_STATIC int UTIL_countPhysicalCores(void)
581{
Sean Purcelle4f32352017-04-13 16:34:28 -0700582 static int numPhysicalCores = 0;
Sean Purcellafa48512017-04-13 12:28:28 -0700583 if (numPhysicalCores != 0) return numPhysicalCores;
584
585 { LPFN_GLPI glpi;
586 BOOL done = FALSE;
587 PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
588 PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL;
589 DWORD returnLength = 0;
590 size_t byteOffset = 0;
591
592 glpi = (LPFN_GLPI)GetProcAddress(GetModuleHandle(TEXT("kernel32")),
593 "GetLogicalProcessorInformation");
594
595 if (glpi == NULL) {
596 goto failed;
597 }
598
599 while(!done) {
600 DWORD rc = glpi(buffer, &returnLength);
601 if (FALSE == rc) {
602 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
603 if (buffer)
604 free(buffer);
605 buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(returnLength);
606
607 if (buffer == NULL) {
608 perror("zstd");
609 exit(1);
610 }
611 } else {
612 /* some other error */
613 goto failed;
614 }
615 } else {
616 done = TRUE;
617 }
618 }
619
Sean Purcell3b6207d2017-04-13 14:03:56 -0700620 ptr = buffer;
Sean Purcellafa48512017-04-13 12:28:28 -0700621
Sean Purcell3b6207d2017-04-13 14:03:56 -0700622 while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength) {
623
624 if (ptr->Relationship == RelationProcessorCore) {
Sean Purcellafa48512017-04-13 12:28:28 -0700625 numPhysicalCores++;
626 }
Sean Purcell3b6207d2017-04-13 14:03:56 -0700627
628 ptr++;
629 byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
Sean Purcellafa48512017-04-13 12:28:28 -0700630 }
631
632 free(buffer);
633
634 return numPhysicalCores;
635 }
636
637failed:
638 /* try to fall back on GetSystemInfo */
Sean Purcell3b6207d2017-04-13 14:03:56 -0700639 { SYSTEM_INFO sysinfo;
640 GetSystemInfo(&sysinfo);
641 numPhysicalCores = sysinfo.dwNumberOfProcessors;
642 if (numPhysicalCores == 0) numPhysicalCores = 1; /* just in case */
643 }
Sean Purcellafa48512017-04-13 12:28:28 -0700644 return numPhysicalCores;
645}
646
647#elif defined(__APPLE__)
648
649#include <sys/sysctl.h>
650
651/* Use apple-provided syscall
652 * see: man 3 sysctl */
653UTIL_STATIC int UTIL_countPhysicalCores(void)
654{
Sean Purcelle4f32352017-04-13 16:34:28 -0700655 static S32 numPhysicalCores = 0; /* apple specifies int32_t */
Sean Purcellafa48512017-04-13 12:28:28 -0700656 if (numPhysicalCores != 0) return numPhysicalCores;
657
Sean Purcellf876f122017-04-13 12:33:45 -0700658 { size_t size = sizeof(S32);
659 int const ret = sysctlbyname("hw.physicalcpu", &numPhysicalCores, &size, NULL, 0);
Sean Purcellafa48512017-04-13 12:28:28 -0700660 if (ret != 0) {
661 if (errno == ENOENT) {
662 /* entry not present, fall back on 1 */
663 numPhysicalCores = 1;
664 } else {
665 perror("zstd: can't get number of physical cpus");
666 exit(1);
667 }
668 }
669
670 return numPhysicalCores;
671 }
672}
673
674#elif defined(__linux__)
675
676/* parse /proc/cpuinfo
677 * siblings / cpu cores should give hyperthreading ratio
678 * otherwise fall back on sysconf */
679UTIL_STATIC int UTIL_countPhysicalCores(void)
680{
Sean Purcelle4f32352017-04-13 16:34:28 -0700681 static int numPhysicalCores = 0;
Sean Purcellafa48512017-04-13 12:28:28 -0700682
683 if (numPhysicalCores != 0) return numPhysicalCores;
684
Sean Purcell9227aae2017-04-13 14:06:40 -0700685 numPhysicalCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
Sean Purcellafa48512017-04-13 12:28:28 -0700686 if (numPhysicalCores == -1) {
687 /* value not queryable, fall back on 1 */
688 return numPhysicalCores = 1;
689 }
690
691 /* try to determine if there's hyperthreading */
692 { FILE* const cpuinfo = fopen("/proc/cpuinfo", "r");
Yann Collet46ac9ad2017-05-15 18:15:08 -0700693#define BUF_SIZE 80
Sean Purcellafa48512017-04-13 12:28:28 -0700694 char buff[BUF_SIZE];
695
696 int siblings = 0;
697 int cpu_cores = 0;
698 int ratio = 1;
699
700 if (cpuinfo == NULL) {
701 /* fall back on the sysconf value */
702 return numPhysicalCores;
703 }
704
705 /* assume the cpu cores/siblings values will be constant across all
706 * present processors */
707 while (!feof(cpuinfo)) {
708 if (fgets(buff, BUF_SIZE, cpuinfo) != NULL) {
709 if (strncmp(buff, "siblings", 8) == 0) {
710 const char* const sep = strchr(buff, ':');
711 if (*sep == '\0') {
712 /* formatting was broken? */
713 goto failed;
714 }
715
716 siblings = atoi(sep + 1);
717 }
718 if (strncmp(buff, "cpu cores", 9) == 0) {
719 const char* const sep = strchr(buff, ':');
720 if (*sep == '\0') {
721 /* formatting was broken? */
722 goto failed;
723 }
724
725 cpu_cores = atoi(sep + 1);
726 }
727 } else if (ferror(cpuinfo)) {
728 /* fall back on the sysconf value */
729 goto failed;
730 }
731 }
732 if (siblings && cpu_cores) {
733 ratio = siblings / cpu_cores;
734 }
735failed:
736 fclose(cpuinfo);
737 return numPhysicalCores = numPhysicalCores / ratio;
738 }
739}
740
Baptiste Daroussin7dd14d02017-04-15 16:25:08 +0200741#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
742
743/* Use apple-provided syscall
744 * see: man 3 sysctl */
745UTIL_STATIC int UTIL_countPhysicalCores(void)
746{
747 static int numPhysicalCores = 0;
748
749 if (numPhysicalCores != 0) return numPhysicalCores;
750
751 numPhysicalCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
752 if (numPhysicalCores == -1) {
753 /* value not queryable, fall back on 1 */
754 return numPhysicalCores = 1;
755 }
756 return numPhysicalCores;
757}
758
Sean Purcellafa48512017-04-13 12:28:28 -0700759#else
760
761UTIL_STATIC int UTIL_countPhysicalCores(void)
762{
763 /* assume 1 */
764 return 1;
765}
766
767#endif
inikep31634032016-05-05 00:25:38 +0200768
inikep69fcd7c2016-04-28 12:23:33 +0200769#if defined (__cplusplus)
770}
771#endif
772
773#endif /* UTIL_H_MODULE */