12 #include <sys/param.h>
14 #include "mythconfig.h"
19 typedef off_t off64_t;
20 # define lseek64(f,o,w) lseek(f,o,w)
25 # define S_IREAD S_IRUSR
28 # define S_IWRITE S_IRUSR
32 #if defined(USING_MINGW)
37 # include <sys/time.h>
38 # include <sys/resource.h>
39 # include <sys/socket.h>
40 # include <sys/wait.h>
43 # define close wsock_close
60 # undef GetCurrentTime
65 # include <winsock2.h>
66 # include <ws2tcpip.h>
80 #if defined(__cplusplus)
83 typedef unsigned int uint;
87 # if defined(__cplusplus)
89 # define setenv(x, y, z) ::SetEnvironmentVariableA(x, y)
90 # define unsetenv(x) 0
107 DWORD spc = 0, bps = 0, fc = 0, c = 0;
109 if (buffer && GetDiskFreeSpaceA(path, &spc, &bps, &fc, &c))
122 #define nice(x) ((int)!::SetPriorityClass(\
123 ::GetCurrentProcess(), ((x) < -10) ? \
124 HIGH_PRIORITY_CLASS : (((x) < 0) ? \
125 ABOVE_NORMAL_PRIORITY_CLASS : (((x) > 10) ? \
126 IDLE_PRIORITY_CLASS : (((x) > 0) ? \
127 BELOW_NORMAL_PRIORITY_CLASS : \
128 NORMAL_PRIORITY_CLASS)))))
129 #define PRIO_PROCESS 0
130 #define setpriority(x, y, z) ((x) == PRIO_PROCESS && y == 0 ? nice(z) : -1)
137 # define SIGUSR1 10 // used to force UPnP mediamap rebuild in the backend
138 # define SIGUSR2 12 // used to restart LIRC as required
139 # define SIGPIPE 13 // not implemented in MINGW, will produce "unable to ignore sigpipe"
148 #define mkfifo(path, mode) \
149 (CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \
150 PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, \
151 1024, 1024, 10000, nullptr) == INVALID_HANDLE_VALUE ? -1 : 0)
154 # define dlopen(x, y) LoadLibraryA((x))
155 # define dlclose(x) !FreeLibrary((HMODULE)(x))
156 # define dlsym(x, y) GetProcAddress((HMODULE)(x), (y))
162 #define DLERR_MAX 512
164 DWORD errCode = GetLastError();
166 if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
167 FORMAT_MESSAGE_IGNORE_INSERTS |
168 FORMAT_MESSAGE_MAX_WIDTH_MASK,
170 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
173 "dlopen()/dlsym() caused error %d", (
int)errCode);
177 # else // __cplusplus
179 # define dlerror() "dlerror() is unimplemented."
180 # endif // __cplusplus
186 # define seteuid(x) 0
190 # define daemon(x, y) -1
191 # define getloadavg(x, y) -1
194 # define WIFEXITED(w) (((w) & 0xff) == 0)
195 # define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
196 # define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
197 # define WEXITSTATUS(w) (((w) >> 8) & 0xff)
198 # define WTERMSIG(w) ((w) & 0x7f)
201 # ifdef LZO_COMPILE_TIME_ASSERT_HEADER
202 # undef LZO_COMPILE_TIME_ASSERT_HEADER
205 # define LZO_COMPILE_TIME_ASSERT_HEADER( a )
207 # ifdef LZO_COMPILE_TIME_ASSERT
208 # undef LZO_COMPILE_TIME_ASSERT
211 # define LZO_COMPILE_TIME_ASSERT( a )
219 #include <sys/time.h>
222 #pragma warning(disable:4786)
232 #define strtoll _strtoi64
233 #define strncasecmp _strnicmp
234 #define snprintf _snprintf
237 using ssize_t = __int64;
245 #if (_MSC_VER < 1800)
246 #define rint( x ) floor(x + 0.5)
247 #define round( x ) floor(x + 0.5)
249 #if ( _MSC_VER < 1700)
250 #define signbit( x ) ( x < 0 )
254 #define M_PI 3.14159265358979323846
257 #define getpid() _getpid()
258 #define ftruncate( fd, fsize ) _chsize( fd, fsize )
262 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
264 # define S_ISCHR(m) 0
269 # define S_ISBLK(m) 0
273 # define S_ISREG(m) 1
278 # define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR )
280 # define S_ISDIR(m) 0
284 using mode_t = uint32_t;
286 #if !defined(__cplusplus) && !defined( inline )
287 # define inline __inline
290 #if !defined(__func__) // C99 & C++11
291 # define __func__ __FUNCTION__
294 # define SIGTRAP SIGBREAK
295 # define STDERR_FILENO (int)GetStdHandle( STD_ERROR_HANDLE )
298 # if !defined(gmtime_r)
301 static __inline
struct tm *gmtime_r(
const time_t *timep,
struct tm *result)
305 struct tm *
tmp = gmtime(timep);
315 # if !defined(localtime_r)
318 static __inline
struct tm *localtime_r(
const time_t *timep,
struct tm *result)
323 struct tm *win_tmp = localtime(timep);
324 memcpy(result, win_tmp,
sizeof(
struct tm));
331 #include <sys/stat.h>
332 # define S_IRUSR _S_IREAD
334 # define lseek64( f, o, w ) _lseeki64( f, o, w )
341 # define O_NONBLOCK 04000