17 # define close wsock_close
34 # undef GetCurrentTime
39 # include <winsock2.h>
40 # include <ws2tcpip.h>
47 # include <sys/time.h>
48 # include <sys/resource.h>
49 # include <sys/socket.h>
50 # include <sys/wait.h>
56 # include <sys/time.h>
61 #pragma warning(disable:4786)
71 #define strtoll _strtoi64
72 #define strncasecmp _strnicmp
73 #define snprintf _snprintf
76 using ssize_t = __int64;
85 #define rint( x ) floor(x + 0.5)
86 #define round( x ) floor(x + 0.5)
88 #if ( _MSC_VER < 1700)
89 #define signbit( x ) ( x < 0 )
93 #define M_PI 3.14159265358979323846
96 #define getpid() _getpid()
97 #define ftruncate( fd, fsize ) _chsize( fd, fsize )
101 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
103 # define S_ISCHR(m) 0
108 # define S_ISBLK(m) 0
112 # define S_ISREG(m) 1
117 # define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR )
119 # define S_ISDIR(m) 0
123 using mode_t = uint32_t;
125 #if !defined(__cplusplus) && !defined( inline )
126 # define inline __inline
129 #if !defined(__func__) // C99 & C++11
130 # define __func__ __FUNCTION__
143 #if defined(__cplusplus) && defined(_WIN32)
146 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
147 #include <QRandomGenerator>
150 {
return QRandomGenerator::global()->generate64(); }
153 static inline void srandom(
unsigned int seed) { qsrand(seed); }
154 static inline long int random(
void) {
return qrand(); }
157 # define setenv(x, y, z) ::SetEnvironmentVariableA(x, y)
158 # define unsetenv(x) 0
160 inline unsigned sleep(
unsigned int x)
180 DWORD spc = 0, bps = 0, fc = 0, c = 0;
182 if (buffer && GetDiskFreeSpaceA(path, &spc, &bps, &fc, &c))
196 #define nice(x) ((int)!::SetPriorityClass(\
197 ::GetCurrentProcess(), ((x) < -10) ? \
198 HIGH_PRIORITY_CLASS : (((x) < 0) ? \
199 ABOVE_NORMAL_PRIORITY_CLASS : (((x) > 10) ? \
200 IDLE_PRIORITY_CLASS : (((x) > 0) ? \
201 BELOW_NORMAL_PRIORITY_CLASS : \
202 NORMAL_PRIORITY_CLASS)))))
203 #define PRIO_PROCESS 0
204 #define setpriority(x, y, z) ((x) == PRIO_PROCESS && y == 0 ? nice(z) : -1)
208 # define SIGTRAP SIGBREAK
209 # define STDERR_FILENO (int)GetStdHandle( STD_ERROR_HANDLE )
217 # define SIGUSR1 10 // used to force UPnP mediamap rebuild in the backend
218 # define SIGUSR2 12 // used to restart LIRC as required
219 # define SIGPIPE 13 // not implemented in MINGW, will produce "unable to ignore sigpipe"
228 #define mkfifo(path, mode) \
229 (int)CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \
230 PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, \
231 1024, 1024, 10000, nullptr)
234 # define dlopen(x, y) LoadLibraryA((x))
235 # define dlclose(x) !FreeLibrary((HMODULE)(x))
236 # define dlsym(x, y) GetProcAddress((HMODULE)(x), (y))
241 #define DLERR_MAX 512
243 DWORD errCode = GetLastError();
245 if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
246 FORMAT_MESSAGE_IGNORE_INSERTS |
247 FORMAT_MESSAGE_MAX_WIDTH_MASK,
249 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
252 "dlopen()/dlsym() caused error %d", (
int)errCode);
256 # else // __cplusplus
257 # define dlerror() "dlerror() is unimplemented."
258 # endif // __cplusplus
264 # define seteuid(x) 0
267 #if defined(_WIN32) && !defined(gmtime_r)
270 static __inline
struct tm *
gmtime_r(
const time_t *timep,
struct tm *result)
274 struct tm *
tmp = gmtime(timep);
284 #if defined(_WIN32) && !defined(localtime_r)
287 static __inline
struct tm *
localtime_r(
const time_t *timep,
struct tm *result)
292 struct tm *win_tmp = localtime(timep);
293 memcpy(result, win_tmp,
sizeof(
struct tm));
302 # define daemon(x, y) -1
303 # define getloadavg(x, y) -1
306 # define WIFEXITED(w) (((w) & 0xff) == 0)
307 # define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
308 # define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
309 # define WEXITSTATUS(w) (((w) >> 8) & 0xff)
310 # define WTERMSIG(w) ((w) & 0x7f)
314 #include <sys/param.h>
316 #include "mythconfig.h"
321 typedef off_t off64_t;
322 #define lseek64(f,o,w) lseek(f,o,w)
325 #if defined(_MSC_VER)
326 #include <sys/stat.h>
327 # define S_IRUSR _S_IREAD
329 # define lseek64( f, o, w ) _lseeki64( f, o, w )
334 # define fseeko(stream, offset, whence) fseeko64(stream, offset, whence)
335 # define ftello(stream) ftello64(stream)
338 #if defined(USING_MINGW) && defined(FILENAME_MAX)
343 static inline int readdir_r(
344 DIR *dirp,
struct dirent *entry,
struct dirent **result)
347 struct dirent *
tmp = readdir(dirp);
350 int offset = offsetof(
struct dirent, d_name);
351 memcpy(entry,
tmp, offset);
352 strncpy(entry->d_name,
tmp->d_name, FILENAME_MAX);
353 tmp->d_name[strlen(entry->d_name)] =
'\0';
369 #define S_IREAD S_IRUSR
372 #define S_IWRITE S_IRUSR
377 # ifdef LZO_COMPILE_TIME_ASSERT_HEADER
378 # undef LZO_COMPILE_TIME_ASSERT_HEADER
381 # define LZO_COMPILE_TIME_ASSERT_HEADER( a )
383 # ifdef LZO_COMPILE_TIME_ASSERT
384 # undef LZO_COMPILE_TIME_ASSERT
387 # define LZO_COMPILE_TIME_ASSERT( a )